home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb.new / gdb-4.0 / gdb / expread.tab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-24  |  74.7 KB  |  2,759 lines

  1.  
  2. /*  A Bison parser, made from ./expread.y  */
  3.  
  4. #define    INT    258
  5. #define    CHAR    259
  6. #define    UINT    260
  7. #define    FLOAT    261
  8. #define    STRING    262
  9. #define    NAME    263
  10. #define    BLOCKNAME    264
  11. #define    TYPENAME    265
  12. #define    NAME_OR_INT    266
  13. #define    NAME_OR_UINT    267
  14. #define    STRUCT    268
  15. #define    UNION    269
  16. #define    ENUM    270
  17. #define    SIZEOF    271
  18. #define    UNSIGNED    272
  19. #define    COLONCOLON    273
  20. #define    ERROR    274
  21. #define    SIGNED    275
  22. #define    LONG    276
  23. #define    SHORT    277
  24. #define    INT_KEYWORD    278
  25. #define    LAST    279
  26. #define    REGNAME    280
  27. #define    VARIABLE    281
  28. #define    ASSIGN_MODIFY    282
  29. #define    THIS    283
  30. #define    ABOVE_COMMA    284
  31. #define    OR    285
  32. #define    AND    286
  33. #define    EQUAL    287
  34. #define    NOTEQUAL    288
  35. #define    LEQ    289
  36. #define    GEQ    290
  37. #define    LSH    291
  38. #define    RSH    292
  39. #define    UNARY    293
  40. #define    INCREMENT    294
  41. #define    DECREMENT    295
  42. #define    ARROW    296
  43.  
  44. #line 29 "./expread.y"
  45.  
  46. #include <stdio.h>
  47. #include "defs.h"
  48. #include "param.h"
  49. #include "symtab.h"
  50. #include "frame.h"
  51. #include "expression.h"
  52. #include "value.h"
  53. #include "command.h"
  54.  
  55. static struct expression *expout;
  56. static int expout_size;
  57. static int expout_ptr;
  58.  
  59. static int yylex ();
  60. static void yyerror ();
  61. static void write_exp_elt ();
  62. static void write_exp_elt_opcode ();
  63. static void write_exp_elt_sym ();
  64. static void write_exp_elt_longcst ();
  65. static void write_exp_elt_dblcst ();
  66. static void write_exp_elt_type ();
  67. static void write_exp_elt_intern ();
  68. static void write_exp_string ();
  69. static void start_arglist ();
  70. static int end_arglist ();
  71. static void free_funcalls ();
  72. static char *copy_name ();
  73. static int parse_number ();
  74.  
  75. /* If this is nonzero, this block is used as the lexical context
  76.    for symbol names.  */
  77.  
  78. static struct block *expression_context_block;
  79.  
  80. /* The innermost context required by the stack and register variables
  81.    we've encountered so far. */
  82. struct block *innermost_block;
  83.  
  84. /* The block in which the most recently discovered symbol was found. */
  85. struct block *block_found;
  86.  
  87. /* Number of arguments seen so far in innermost function call.  */
  88. static int arglist_len;
  89.  
  90. /* Data structure for saving values of arglist_len
  91.    for function calls whose arguments contain other function calls.  */
  92.  
  93. struct funcall
  94.   {
  95.     struct funcall *next;
  96.     int arglist_len;
  97.   };
  98.  
  99. struct funcall *funcall_chain;
  100.  
  101. /* This kind of datum is used to represent the name
  102.    of a symbol token.  */
  103.  
  104. struct stoken
  105.   {
  106.     char *ptr;
  107.     int length;
  108.   };
  109.  
  110. struct ttype
  111.   {
  112.     struct stoken stoken;
  113.     struct type *type;
  114.   };
  115.  
  116. struct symtoken
  117.   {
  118.     struct stoken stoken;
  119.     struct symbol *sym;
  120.     int is_a_field_of_this;
  121.   };
  122.  
  123. /* For parsing of complicated types.
  124.    An array should be preceded in the list by the size of the array.  */
  125. enum type_pieces
  126.   {tp_end = -1, tp_pointer, tp_reference, tp_array, tp_function};
  127. /* The stack can contain either an enum type_pieces or an int.  */
  128. union type_stack_elt {
  129.   enum type_pieces piece;
  130.   int int_val;
  131. };
  132. static union type_stack_elt *type_stack;
  133. static int type_stack_depth, type_stack_size;
  134.  
  135. static void push_type ();
  136. static void push_type_int ();
  137. static enum type_pieces pop_type ();
  138. static int pop_type_int ();
  139.  
  140. /* Allow debugging of parsing.  */
  141. #define YYDEBUG 1
  142.  
  143. #line 132 "./expread.y"
  144. typedef union
  145.   {
  146.     LONGEST lval;
  147.     unsigned LONGEST ulval;
  148.     double dval;
  149.     struct symbol *sym;
  150.     struct type *tval;
  151.     struct stoken sval;
  152.     struct ttype tsym;
  153.     struct symtoken ssym;
  154.     int voidval;
  155.     struct block *bval;
  156.     enum exp_opcode opcode;
  157.     struct internalvar *ivar;
  158.  
  159.     struct type **tvec;
  160.     int *ivec;
  161.   } YYSTYPE;
  162.  
  163. #ifndef YYLTYPE
  164. typedef
  165.   struct yyltype
  166.     {
  167.       int timestamp;
  168.       int first_line;
  169.       int first_column;
  170.       int last_line;
  171.       int last_column;
  172.       char *text;
  173.    }
  174.   yyltype;
  175.  
  176. #define YYLTYPE yyltype
  177. #endif
  178.  
  179. #include <stdio.h>
  180.  
  181. #ifndef __STDC__
  182. #define const
  183. #endif
  184.  
  185.  
  186.  
  187. #define    YYFINAL        197
  188. #define    YYFLAG        -32768
  189. #define    YYNTBASE    66
  190.  
  191. #define YYTRANSLATE(x) ((unsigned)(x) <= 296 ? yytranslate[x] : 84)
  192.  
  193. static const char yytranslate[] = {     0,
  194.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  195.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  196.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  197.      2,     2,    59,     2,     2,     2,    51,    37,     2,    58,
  198.     62,    49,    47,    29,    48,    56,    50,     2,     2,     2,
  199.      2,     2,     2,     2,     2,     2,     2,    65,     2,    40,
  200.     31,    41,    32,    46,     2,     2,     2,     2,     2,     2,
  201.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  202.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  203.     57,     2,    61,    36,     2,     2,     2,     2,     2,     2,
  204.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  205.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  206.      2,     2,    63,    35,    64,    60,     2,     2,     2,     2,
  207.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  208.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  209.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  210.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  211.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  212.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  213.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  214.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  215.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  216.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  217.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  218.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  219.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  220.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  221.     16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
  222.     26,    27,    28,    30,    33,    34,    38,    39,    42,    43,
  223.     44,    45,    52,    53,    54,    55
  224. };
  225.  
  226. static const short yyrline[] = {     0,
  227.    225,   229,   230,   235,   238,   241,   245,   249,   253,   257,
  228.    261,   265,   269,   273,   279,   283,   289,   293,   297,   301,
  229.    307,   310,   314,   318,   324,   330,   336,   340,   344,   348,
  230.    352,   356,   360,   364,   368,   372,   376,   380,   384,   388,
  231.    392,   396,   400,   404,   408,   412,   416,   420,   426,   436,
  232.    449,   461,   474,   481,   488,   491,   497,   503,   509,   516,
  233.    523,   530,   548,   558,   570,   583,   601,   647,   741,   742,
  234.    777,   779,   781,   783,   785,   788,   790,   795,   801,   803,
  235.    807,   809,   813,   817,   818,   820,   822,   825,   832,   834,
  236.    836,   838,   840,   842,   844,   846,   848,   850,   852,   854,
  237.    856,   859,   862,   865,   867,   869,   871,   875,   876,   882,
  238.    888,   897,   902,   909,   910,   911,   912,   913,   916,   917
  239. };
  240.  
  241. static const char * const yytname[] = {     0,
  242. "error","$illegal.","INT","CHAR","UINT","FLOAT","STRING","NAME","BLOCKNAME","TYPENAME",
  243. "NAME_OR_INT","NAME_OR_UINT","STRUCT","UNION","ENUM","SIZEOF","UNSIGNED","COLONCOLON","ERROR","SIGNED",
  244. "LONG","SHORT","INT_KEYWORD","LAST","REGNAME","VARIABLE","ASSIGN_MODIFY","THIS","','","ABOVE_COMMA",
  245. "'='","'?'","OR","AND","'|'","'^'","'&'","EQUAL","NOTEQUAL","'<'",
  246. "'>'","LEQ","GEQ","LSH","RSH","'@'","'+'","'-'","'*'","'/'",
  247. "'%'","UNARY","INCREMENT","DECREMENT","ARROW","'.'","'['","'('","'!'","'~'",
  248. "']'","')'","'{'","'}'","':'","start"
  249. };
  250.  
  251. static const short yyr1[] = {     0,
  252.     66,    67,    67,    68,    68,    68,    68,    68,    68,    68,
  253.     68,    68,    68,    68,    68,    68,    68,    68,    69,    68,
  254.     70,    70,    70,    68,    68,    68,    68,    68,    68,    68,
  255.     68,    68,    68,    68,    68,    68,    68,    68,    68,    68,
  256.     68,    68,    68,    68,    68,    68,    68,    68,    68,    68,
  257.     68,    68,    68,    68,    68,    68,    68,    68,    68,    68,
  258.     68,    71,    71,    72,    72,    72,    72,    72,    73,    73,
  259.     74,    74,    74,    74,    74,    75,    75,    75,    75,    75,
  260.     76,    76,    77,    78,    78,    78,    78,    78,    79,    79,
  261.     79,    79,    79,    79,    79,    79,    79,    79,    79,    79,
  262.     79,    79,    79,    79,    79,    79,    79,    80,    80,    80,
  263.     80,    81,    81,    82,    82,    82,    82,    82,    83,    83
  264. };
  265.  
  266. static const short yyr2[] = {     0,
  267.      1,     1,     3,     2,     2,     2,     2,     2,     2,     2,
  268.      2,     2,     2,     3,     4,     3,     4,     4,     0,     5,
  269.      0,     1,     3,     4,     4,     3,     3,     3,     3,     3,
  270.      3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
  271.      3,     3,     3,     3,     3,     5,     3,     3,     1,     1,
  272.      1,     1,     1,     1,     1,     1,     1,     1,     4,     1,
  273.      1,     1,     3,     3,     3,     4,     2,     1,     1,     2,
  274.      1,     2,     1,     2,     1,     3,     2,     1,     2,     1,
  275.      2,     3,     2,     1,     3,     6,     8,     9,     1,     1,
  276.      1,     1,     2,     3,     2,     3,     3,     4,     2,     3,
  277.      2,     2,     2,     2,     1,     2,     1,     1,     1,     1,
  278.      1,     1,     3,     1,     1,     1,     1,     1,     1,     1
  279. };
  280.  
  281. static const short yydefact[] = {     0,
  282.     49,    53,    51,    54,    60,   119,   120,    89,    50,    52,
  283.      0,     0,     0,     0,   105,     0,   107,    91,    92,    90,
  284.     56,    57,    58,    61,     0,     0,     0,     0,     0,     0,
  285.      0,     0,     0,     1,     2,     0,    55,     0,    68,   114,
  286.    115,   116,   117,   118,   101,   102,   103,     0,    13,   108,
  287.    110,   111,   109,   104,    67,   110,   111,   106,    95,    93,
  288.     99,     5,     6,     4,     9,    10,     0,    84,     0,    69,
  289.      7,     8,     0,    69,     0,     0,     0,     0,     0,     0,
  290.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  291.      0,     0,     0,     0,     0,     0,     0,    11,    12,     0,
  292.      0,     0,    19,     0,     0,     0,    97,    94,   100,    96,
  293.     26,     0,     0,     0,    73,    71,     0,     0,    70,    75,
  294.     78,    80,     0,     0,     3,    48,    47,     0,    45,    44,
  295.     43,    42,    41,    35,    36,    39,    40,    37,    38,    33,
  296.     34,    27,    31,    32,    28,    29,    30,     0,    14,     0,
  297.     16,     0,    21,    64,     0,    65,    59,    98,     0,    25,
  298.     85,    74,    72,     0,    81,    83,     0,     0,    77,    79,
  299.     24,     0,    15,    17,    18,    22,     0,    66,     0,    82,
  300.     76,    46,     0,    20,     0,    23,    86,     0,    87,   112,
  301.      0,     0,    88,   113,     0,     0,     0
  302. };
  303.  
  304. static const short yydefgoto[] = {   195,
  305.     67,    35,   153,   177,    36,    37,    68,   119,   120,   121,
  306.    122,    69,    38,    54,   191,   156,    39
  307. };
  308.  
  309. static const short yypact[] = {   167,
  310. -32768,-32768,-32768,-32768,-32768,-32768,     7,-32768,-32768,-32768,
  311.     22,    22,    22,   228,   190,    22,   245,   119,    -7,-32768,
  312. -32768,-32768,-32768,-32768,   167,   167,   167,   167,   167,   167,
  313.    167,   167,   528,    60,   303,    33,-32768,    76,-32768,-32768,
  314. -32768,-32768,-32768,-32768,-32768,-32768,-32768,   167,   216,-32768,
  315.    134,    77,-32768,-32768,-32768,-32768,-32768,-32768,    78,-32768,
  316. -32768,   216,   216,   216,   216,   216,    59,-32768,   -52,    75,
  317.    216,   216,   -55,    80,   167,   167,   167,   167,   167,   167,
  318.    167,   167,   167,   167,   167,   167,   167,   167,   167,   167,
  319.    167,   167,   167,   167,   167,   167,   167,-32768,-32768,   198,
  320.    249,   167,-32768,    22,   138,   -34,    90,-32768,-32768,-32768,
  321. -32768,   528,   167,    96,   165,   165,    26,   104,-32768,   -50,
  322. -32768,-32768,   167,    47,   303,   303,   303,   268,   355,   379,
  323.    402,   424,   445,   464,   464,   479,   479,   479,   479,   506,
  324.    506,   518,   529,   529,   216,   216,   216,   167,-32768,   167,
  325. -32768,    -2,   167,    98,    22,-32768,    32,-32768,   113,   216,
  326. -32768,-32768,-32768,    62,-32768,-32768,    82,   106,-32768,-32768,
  327.    216,   167,   216,   216,-32768,   303,    68,-32768,   137,-32768,
  328. -32768,   330,   167,-32768,   132,   303,   139,   105,-32768,   141,
  329.     73,   528,-32768,   141,   196,   201,-32768
  330. };
  331.  
  332. static const short yypgoto[] = {-32768,
  333.      1,   -14,-32768,-32768,-32768,-32768,-32768,    36,-32768,    83,
  334.     85,   -29,   -28,   200,-32768,    10,-32768
  335. };
  336.  
  337.  
  338. #define    YYLAST        587
  339.  
  340.  
  341. static const short yytable[] = {    49,
  342.     34,    70,   112,    73,    74,   112,   117,   168,   123,   113,
  343.     62,    63,    64,    65,    66,    61,    71,    72,   106,    70,
  344.     45,    46,    47,   112,   -62,    55,    75,   157,   164,    40,
  345.     41,    42,    43,    44,     1,     2,     3,     4,     5,     6,
  346.      7,     8,     9,    10,    11,    12,    13,    14,    15,    16,
  347.    104,    17,    18,    19,    20,    21,    22,    23,   175,    24,
  348.    125,   126,   127,   128,   129,   130,   131,   132,   133,   134,
  349.    135,   136,   137,   138,   139,   140,   141,   142,   143,   144,
  350.    145,   146,   147,   159,    28,    29,   165,    75,    75,    30,
  351.     31,    32,   114,   105,    33,   161,   183,   124,   160,   109,
  352.    110,   192,   152,    40,    41,    42,    43,    44,   171,   149,
  353.    151,   115,   158,   154,     8,   -63,   115,    11,    12,    13,
  354.    111,    15,   180,   116,    17,    18,    19,    20,   116,   184,
  355.    179,   117,   118,   173,   193,   174,   117,   118,   176,    59,
  356.    115,    60,   160,   181,   161,    40,    41,    42,    43,    44,
  357.    162,   163,   116,   167,   107,   155,   108,   182,   190,    74,
  358.    117,   118,   194,    74,   178,   166,   189,   166,   186,     1,
  359.      2,     3,     4,     5,     6,     7,     8,     9,    10,    11,
  360.     12,    13,    14,    15,    16,   185,    17,    18,    19,    20,
  361.     21,    22,    23,   187,    24,   196,   188,   155,   112,    50,
  362.    197,   115,   169,    25,   170,    40,    41,    42,    43,    44,
  363.     51,    52,    53,   116,    26,    27,    58,     0,     0,    28,
  364.     29,   117,   118,     0,    30,    31,    32,     0,     0,    33,
  365.      1,     2,     3,     4,     5,     6,     7,     8,     9,    10,
  366.     11,    12,    13,    14,    15,    16,   148,    17,    18,    19,
  367.     20,    21,    22,    23,    50,    24,    40,    41,    42,    43,
  368.     44,     0,     0,     0,    25,    56,    57,    53,    98,    99,
  369.    100,   101,   102,   103,     0,    26,    27,     0,     0,     0,
  370.     28,    29,     0,     0,     0,    48,    31,    32,     0,     0,
  371.     33,     0,     0,     0,    76,     0,     0,   150,    77,    78,
  372.     79,    80,    81,    82,    83,    84,    85,    86,    87,    88,
  373.     89,    90,    91,    92,    93,    94,    95,    96,    97,     0,
  374.     98,    99,   100,   101,   102,   103,     0,     0,     0,    76,
  375.      0,     0,   172,    77,    78,    79,    80,    81,    82,    83,
  376.     84,    85,    86,    87,    88,    89,    90,    91,    92,    93,
  377.     94,    95,    96,    97,     0,    98,    99,   100,   101,   102,
  378.    103,    78,    79,    80,    81,    82,    83,    84,    85,    86,
  379.     87,    88,    89,    90,    91,    92,    93,    94,    95,    96,
  380.     97,     0,    98,    99,   100,   101,   102,   103,    80,    81,
  381.     82,    83,    84,    85,    86,    87,    88,    89,    90,    91,
  382.     92,    93,    94,    95,    96,    97,     0,    98,    99,   100,
  383.    101,   102,   103,    81,    82,    83,    84,    85,    86,    87,
  384.     88,    89,    90,    91,    92,    93,    94,    95,    96,    97,
  385.      0,    98,    99,   100,   101,   102,   103,    82,    83,    84,
  386.     85,    86,    87,    88,    89,    90,    91,    92,    93,    94,
  387.     95,    96,    97,     0,    98,    99,   100,   101,   102,   103,
  388.     83,    84,    85,    86,    87,    88,    89,    90,    91,    92,
  389.     93,    94,    95,    96,    97,     0,    98,    99,   100,   101,
  390.    102,   103,    84,    85,    86,    87,    88,    89,    90,    91,
  391.     92,    93,    94,    95,    96,    97,     0,    98,    99,   100,
  392.    101,   102,   103,    86,    87,    88,    89,    90,    91,    92,
  393.     93,    94,    95,    96,    97,     0,    98,    99,   100,   101,
  394.    102,   103,    90,    91,    92,    93,    94,    95,    96,    97,
  395.      0,    98,    99,   100,   101,   102,   103,     8,     0,     0,
  396.     11,    12,    13,     0,    15,     0,     0,    17,    18,    19,
  397.     20,    92,    93,    94,    95,    96,    97,     0,    98,    99,
  398.    100,   101,   102,   103,    93,    94,    95,    96,    97,     0,
  399.     98,    99,   100,   101,   102,   103,     0,    95,    96,    97,
  400.      0,    98,    99,   100,   101,   102,   103
  401. };
  402.  
  403. static const short yycheck[] = {    14,
  404.      0,    30,    58,    33,    33,    58,    57,    58,    64,    62,
  405.     25,    26,    27,    28,    29,    23,    31,    32,    48,    48,
  406.     11,    12,    13,    58,    18,    16,    29,    62,     3,     8,
  407.      9,    10,    11,    12,     3,     4,     5,     6,     7,     8,
  408.      9,    10,    11,    12,    13,    14,    15,    16,    17,    18,
  409.     18,    20,    21,    22,    23,    24,    25,    26,    61,    28,
  410.     75,    76,    77,    78,    79,    80,    81,    82,    83,    84,
  411.     85,    86,    87,    88,    89,    90,    91,    92,    93,    94,
  412.     95,    96,    97,   112,    53,    54,    61,    29,    29,    58,
  413.     59,    60,    18,    18,    63,    49,    29,    18,   113,    23,
  414.     23,    29,   102,     8,     9,    10,    11,    12,   123,   100,
  415.    101,    37,    23,   104,    10,    18,    37,    13,    14,    15,
  416.     62,    17,    61,    49,    20,    21,    22,    23,    49,    62,
  417.     18,    57,    58,   148,    62,   150,    57,    58,   153,    21,
  418.     37,    23,   157,    62,    49,     8,     9,    10,    11,    12,
  419.    115,   116,    49,   118,    21,    60,    23,   172,   188,   188,
  420.     57,    58,   192,   192,   155,    62,    62,    62,   183,     3,
  421.      4,     5,     6,     7,     8,     9,    10,    11,    12,    13,
  422.     14,    15,    16,    17,    18,    49,    20,    21,    22,    23,
  423.     24,    25,    26,    62,    28,     0,    58,    60,    58,    10,
  424.      0,    37,   120,    37,   120,     8,     9,    10,    11,    12,
  425.     21,    22,    23,    49,    48,    49,    17,    -1,    -1,    53,
  426.     54,    57,    58,    -1,    58,    59,    60,    -1,    -1,    63,
  427.      3,     4,     5,     6,     7,     8,     9,    10,    11,    12,
  428.     13,    14,    15,    16,    17,    18,    49,    20,    21,    22,
  429.     23,    24,    25,    26,    10,    28,     8,     9,    10,    11,
  430.     12,    -1,    -1,    -1,    37,    21,    22,    23,    53,    54,
  431.     55,    56,    57,    58,    -1,    48,    49,    -1,    -1,    -1,
  432.     53,    54,    -1,    -1,    -1,    58,    59,    60,    -1,    -1,
  433.     63,    -1,    -1,    -1,    27,    -1,    -1,    49,    31,    32,
  434.     33,    34,    35,    36,    37,    38,    39,    40,    41,    42,
  435.     43,    44,    45,    46,    47,    48,    49,    50,    51,    -1,
  436.     53,    54,    55,    56,    57,    58,    -1,    -1,    -1,    27,
  437.     -1,    -1,    65,    31,    32,    33,    34,    35,    36,    37,
  438.     38,    39,    40,    41,    42,    43,    44,    45,    46,    47,
  439.     48,    49,    50,    51,    -1,    53,    54,    55,    56,    57,
  440.     58,    32,    33,    34,    35,    36,    37,    38,    39,    40,
  441.     41,    42,    43,    44,    45,    46,    47,    48,    49,    50,
  442.     51,    -1,    53,    54,    55,    56,    57,    58,    34,    35,
  443.     36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
  444.     46,    47,    48,    49,    50,    51,    -1,    53,    54,    55,
  445.     56,    57,    58,    35,    36,    37,    38,    39,    40,    41,
  446.     42,    43,    44,    45,    46,    47,    48,    49,    50,    51,
  447.     -1,    53,    54,    55,    56,    57,    58,    36,    37,    38,
  448.     39,    40,    41,    42,    43,    44,    45,    46,    47,    48,
  449.     49,    50,    51,    -1,    53,    54,    55,    56,    57,    58,
  450.     37,    38,    39,    40,    41,    42,    43,    44,    45,    46,
  451.     47,    48,    49,    50,    51,    -1,    53,    54,    55,    56,
  452.     57,    58,    38,    39,    40,    41,    42,    43,    44,    45,
  453.     46,    47,    48,    49,    50,    51,    -1,    53,    54,    55,
  454.     56,    57,    58,    40,    41,    42,    43,    44,    45,    46,
  455.     47,    48,    49,    50,    51,    -1,    53,    54,    55,    56,
  456.     57,    58,    44,    45,    46,    47,    48,    49,    50,    51,
  457.     -1,    53,    54,    55,    56,    57,    58,    10,    -1,    -1,
  458.     13,    14,    15,    -1,    17,    -1,    -1,    20,    21,    22,
  459.     23,    46,    47,    48,    49,    50,    51,    -1,    53,    54,
  460.     55,    56,    57,    58,    47,    48,    49,    50,    51,    -1,
  461.     53,    54,    55,    56,    57,    58,    -1,    49,    50,    51,
  462.     -1,    53,    54,    55,    56,    57,    58
  463. };
  464. #define YYPURE 1
  465.  
  466. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  467. #line 3 "bison.simple"
  468.  
  469. /* Skeleton output parser for bison,
  470.    Copyright (C) 1984 Bob Corbett and Richard Stallman
  471.  
  472.    This program is free software; you can redistribute it and/or modify
  473.    it under the terms of the GNU General Public License as published by
  474.    the Free Software Foundation; either version 1, or (at your option)
  475.    any later version.
  476.  
  477.    This program is distributed in the hope that it will be useful,
  478.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  479.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  480.    GNU General Public License for more details.
  481.  
  482.    You should have received a copy of the GNU General Public License
  483.    along with this program; if not, write to the Free Software
  484.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  485.  
  486.  
  487. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  488. #include <alloca.h>
  489. #endif
  490.  
  491. /* This is the parser code that is written into each bison parser
  492.   when the %semantic_parser declaration is not specified in the grammar.
  493.   It was written by Richard Stallman by simplifying the hairy parser
  494.   used when %semantic_parser is specified.  */
  495.  
  496. /* Note: there must be only one dollar sign in this file.
  497.    It is replaced by the list of actions, each action
  498.    as one case of the switch.  */
  499.  
  500. #define yyerrok        (yyerrstatus = 0)
  501. #define yyclearin    (yychar = YYEMPTY)
  502. #define YYEMPTY        -2
  503. #define YYEOF        0
  504. #define YYFAIL        goto yyerrlab;
  505. #define YYACCEPT    return(0)
  506. #define YYABORT     return(1)
  507. #define YYERROR        goto yyerrlab
  508.  
  509. #define YYTERROR    1
  510. #define YYERRCODE    256
  511.  
  512. #ifndef YYIMPURE
  513. #define YYLEX        yylex()
  514. #endif
  515.  
  516. #ifndef YYPURE
  517. #define YYLEX        yylex(&yylval, &yylloc)
  518. #endif
  519.  
  520. /* If nonreentrant, generate the variables here */
  521.  
  522. #ifndef YYIMPURE
  523.  
  524. int    yychar;            /*  the lookahead symbol        */
  525. YYSTYPE    yylval;            /*  the semantic value of the        */
  526.                 /*  lookahead symbol            */
  527.  
  528. YYLTYPE yylloc;            /*  location data for the lookahead    */
  529.                 /*  symbol                */
  530.  
  531. int yynerrs;            /*  number of parse errors so far       */
  532. #endif  /* YYIMPURE */
  533.  
  534. #if YYDEBUG != 0
  535. int yydebug;            /*  nonzero means print parse trace    */
  536. /* Since this is uninitialized, it does not stop multiple parsers
  537.    from coexisting.  */
  538. #endif
  539.  
  540. /*  YYMAXDEPTH indicates the initial size of the parser's stacks    */
  541.  
  542. #ifndef    YYMAXDEPTH
  543. #define YYMAXDEPTH 200
  544. #endif
  545.  
  546. /*  YYMAXLIMIT is the maximum size the stacks can grow to
  547.     (effective only if the built-in stack extension method is used).  */
  548.  
  549. #ifndef YYMAXLIMIT
  550. #define YYMAXLIMIT 10000
  551. #endif
  552.  
  553.  
  554. #line 90 "bison.simple"
  555. int
  556. yyparse()
  557. {
  558.   register int yystate;
  559.   register int yyn;
  560.   register short *yyssp;
  561.   register YYSTYPE *yyvsp;
  562.   YYLTYPE *yylsp;
  563.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  564.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  565.  
  566.   short    yyssa[YYMAXDEPTH];    /*  the state stack            */
  567.   YYSTYPE yyvsa[YYMAXDEPTH];    /*  the semantic value stack        */
  568.   YYLTYPE yylsa[YYMAXDEPTH];    /*  the location stack            */
  569.  
  570.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  571.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  572.   YYLTYPE *yyls = yylsa;
  573.  
  574.   int yymaxdepth = YYMAXDEPTH;
  575.  
  576. #ifndef YYPURE
  577.   int yychar;
  578.   YYSTYPE yylval;
  579.   YYLTYPE yylloc;
  580.   int yynerrs;
  581. #endif
  582.  
  583.   YYSTYPE yyval;        /*  the variable used to return        */
  584.                 /*  semantic values from the action    */
  585.                 /*  routines                */
  586.  
  587.   int yylen;
  588.  
  589. #if YYDEBUG != 0
  590.   if (yydebug)
  591.     fprintf(stderr, "Starting parse\n");
  592. #endif
  593.  
  594.   yystate = 0;
  595.   yyerrstatus = 0;
  596.   yynerrs = 0;
  597.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  598.  
  599.   /* Initialize stack pointers.
  600.      Waste one element of value and location stack
  601.      so that they stay on the same level as the state stack.  */
  602.  
  603.   yyssp = yyss - 1;
  604.   yyvsp = yyvs;
  605.   yylsp = yyls;
  606.  
  607. /* Push a new state, which is found in  yystate  .  */
  608. /* In all cases, when you get here, the value and location stacks
  609.    have just been pushed. so pushing a state here evens the stacks.  */
  610. yynewstate:
  611.  
  612.   *++yyssp = yystate;
  613.  
  614.   if (yyssp >= yyss + yymaxdepth - 1)
  615.     {
  616.       /* Give user a chance to reallocate the stack */
  617.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  618.       YYSTYPE *yyvs1 = yyvs;
  619.       YYLTYPE *yyls1 = yyls;
  620.       short *yyss1 = yyss;
  621.  
  622.       /* Get the current used size of the three stacks, in elements.  */
  623.       int size = yyssp - yyss + 1;
  624.  
  625. #ifdef yyoverflow
  626.       /* Each stack pointer address is followed by the size of
  627.      the data in use in that stack, in bytes.  */
  628.       yyoverflow("parser stack overflow",
  629.          &yyss1, size * sizeof (*yyssp),
  630.          &yyvs1, size * sizeof (*yyvsp),
  631.          &yyls1, size * sizeof (*yylsp),
  632.          &yymaxdepth);
  633.  
  634.       yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
  635. #else /* no yyoverflow */
  636.       /* Extend the stack our own way.  */
  637.       if (yymaxdepth >= YYMAXLIMIT)
  638.     yyerror("parser stack overflow");
  639.       yymaxdepth *= 2;
  640.       if (yymaxdepth > YYMAXLIMIT)
  641.     yymaxdepth = YYMAXLIMIT;
  642.       yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
  643.       bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  644.       yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
  645.       bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  646. #ifdef YYLSP_NEEDED
  647.       yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
  648.       bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  649. #endif
  650. #endif /* no yyoverflow */
  651.  
  652.       yyssp = yyss + size - 1;
  653.       yyvsp = yyvs + size - 1;
  654. #ifdef YYLSP_NEEDED
  655.       yylsp = yyls + size - 1;
  656. #endif
  657.  
  658. #if YYDEBUG != 0
  659.       if (yydebug)
  660.     fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
  661. #endif
  662.  
  663.       if (yyssp >= yyss + yymaxdepth - 1)
  664.     YYABORT;
  665.     }
  666.  
  667. #if YYDEBUG != 0
  668.   if (yydebug)
  669.     fprintf(stderr, "Entering state %d\n", yystate);
  670. #endif
  671.  
  672. /* Do appropriate processing given the current state.  */
  673. /* Read a lookahead token if we need one and don't already have one.  */
  674. yyresume:
  675.  
  676.   /* First try to decide what to do without reference to lookahead token.  */
  677.  
  678.   yyn = yypact[yystate];
  679.   if (yyn == YYFLAG)
  680.     goto yydefault;
  681.  
  682.   /* Not known => get a lookahead token if don't already have one.  */
  683.  
  684.   /* yychar is either YYEMPTY or YYEOF
  685.      or a valid token in external form.  */
  686.  
  687.   if (yychar == YYEMPTY)
  688.     {
  689. #if YYDEBUG != 0
  690.       if (yydebug)
  691.     fprintf(stderr, "Reading a token: ");
  692. #endif
  693.       yychar = YYLEX;
  694.     }
  695.  
  696.   /* Convert token to internal form (in yychar1) for indexing tables with */
  697.  
  698.   if (yychar <= 0)        /* This means end of input. */
  699.     {
  700.       yychar1 = 0;
  701.       yychar = YYEOF;        /* Don't call YYLEX any more */
  702.  
  703. #if YYDEBUG != 0
  704.       if (yydebug)
  705.     fprintf(stderr, "Now at end of input.\n");
  706. #endif
  707.     }
  708.   else
  709.     {
  710.       yychar1 = YYTRANSLATE(yychar);
  711.  
  712. #if YYDEBUG != 0
  713.       if (yydebug)
  714.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  715. #endif
  716.     }
  717.  
  718.   yyn += yychar1;
  719.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  720.     goto yydefault;
  721.  
  722.   yyn = yytable[yyn];
  723.  
  724.   /* yyn is what to do for this token type in this state.
  725.      Negative => reduce, -yyn is rule number.
  726.      Positive => shift, yyn is new state.
  727.        New state is final state => don't bother to shift,
  728.        just return success.
  729.      0, or most negative number => error.  */
  730.  
  731.   if (yyn < 0)
  732.     {
  733.       if (yyn == YYFLAG)
  734.     goto yyerrlab;
  735.       yyn = -yyn;
  736.       goto yyreduce;
  737.     }
  738.   else if (yyn == 0)
  739.     goto yyerrlab;
  740.  
  741.   if (yyn == YYFINAL)
  742.     YYACCEPT;
  743.  
  744.   /* Shift the lookahead token.  */
  745.  
  746. #if YYDEBUG != 0
  747.   if (yydebug)
  748.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  749. #endif
  750.  
  751.   /* Discard the token being shifted unless it is eof.  */
  752.   if (yychar != YYEOF)
  753.     yychar = YYEMPTY;
  754.  
  755.   *++yyvsp = yylval;
  756. #ifdef YYLSP_NEEDED
  757.   *++yylsp = yylloc;
  758. #endif
  759.  
  760.   /* count tokens shifted since error; after three, turn off error status.  */
  761.   if (yyerrstatus) yyerrstatus--;
  762.  
  763.   yystate = yyn;
  764.   goto yynewstate;
  765.  
  766. /* Do the default action for the current state.  */
  767. yydefault:
  768.  
  769.   yyn = yydefact[yystate];
  770.   if (yyn == 0)
  771.     goto yyerrlab;
  772.  
  773. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  774. yyreduce:
  775.   yylen = yyr2[yyn];
  776.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  777.  
  778. #if YYDEBUG != 0
  779.   if (yydebug)
  780.     {
  781.       if (yylen == 1)
  782.     fprintf (stderr, "Reducing 1 value via line %d, ",
  783.          yyrline[yyn]);
  784.       else
  785.     fprintf (stderr, "Reducing %d values via line %d, ",
  786.          yylen, yyrline[yyn]);
  787.     }
  788. #endif
  789.  
  790.  
  791.   switch (yyn) {
  792.  
  793. case 3:
  794. #line 231 "./expread.y"
  795. { write_exp_elt_opcode (BINOP_COMMA); ;
  796.     break;}
  797. case 4:
  798. #line 236 "./expread.y"
  799. { write_exp_elt_opcode (UNOP_IND); ;
  800.     break;}
  801. case 5:
  802. #line 239 "./expread.y"
  803. { write_exp_elt_opcode (UNOP_ADDR); ;
  804.     break;}
  805. case 6:
  806. #line 242 "./expread.y"
  807. { write_exp_elt_opcode (UNOP_NEG); ;
  808.     break;}
  809. case 7:
  810. #line 246 "./expread.y"
  811. { write_exp_elt_opcode (UNOP_ZEROP); ;
  812.     break;}
  813. case 8:
  814. #line 250 "./expread.y"
  815. { write_exp_elt_opcode (UNOP_LOGNOT); ;
  816.     break;}
  817. case 9:
  818. #line 254 "./expread.y"
  819. { write_exp_elt_opcode (UNOP_PREINCREMENT); ;
  820.     break;}
  821. case 10:
  822. #line 258 "./expread.y"
  823. { write_exp_elt_opcode (UNOP_PREDECREMENT); ;
  824.     break;}
  825. case 11:
  826. #line 262 "./expread.y"
  827. { write_exp_elt_opcode (UNOP_POSTINCREMENT); ;
  828.     break;}
  829. case 12:
  830. #line 266 "./expread.y"
  831. { write_exp_elt_opcode (UNOP_POSTDECREMENT); ;
  832.     break;}
  833. case 13:
  834. #line 270 "./expread.y"
  835. { write_exp_elt_opcode (UNOP_SIZEOF); ;
  836.     break;}
  837. case 14:
  838. #line 274 "./expread.y"
  839. { write_exp_elt_opcode (STRUCTOP_PTR);
  840.               write_exp_string (yyvsp[0].sval);
  841.               write_exp_elt_opcode (STRUCTOP_PTR); ;
  842.     break;}
  843. case 15:
  844. #line 280 "./expread.y"
  845. { write_exp_elt_opcode (STRUCTOP_MPTR); ;
  846.     break;}
  847. case 16:
  848. #line 284 "./expread.y"
  849. { write_exp_elt_opcode (STRUCTOP_STRUCT);
  850.               write_exp_string (yyvsp[0].sval);
  851.               write_exp_elt_opcode (STRUCTOP_STRUCT); ;
  852.     break;}
  853. case 17:
  854. #line 290 "./expread.y"
  855. { write_exp_elt_opcode (STRUCTOP_MEMBER); ;
  856.     break;}
  857. case 18:
  858. #line 294 "./expread.y"
  859. { write_exp_elt_opcode (BINOP_SUBSCRIPT); ;
  860.     break;}
  861. case 19:
  862. #line 300 "./expread.y"
  863. { start_arglist (); ;
  864.     break;}
  865. case 20:
  866. #line 302 "./expread.y"
  867. { write_exp_elt_opcode (OP_FUNCALL);
  868.               write_exp_elt_longcst ((LONGEST) end_arglist ());
  869.               write_exp_elt_opcode (OP_FUNCALL); ;
  870.     break;}
  871. case 22:
  872. #line 311 "./expread.y"
  873. { arglist_len = 1; ;
  874.     break;}
  875. case 23:
  876. #line 315 "./expread.y"
  877. { arglist_len++; ;
  878.     break;}
  879. case 24:
  880. #line 319 "./expread.y"
  881. { write_exp_elt_opcode (UNOP_MEMVAL);
  882.               write_exp_elt_type (yyvsp[-2].tval);
  883.               write_exp_elt_opcode (UNOP_MEMVAL); ;
  884.     break;}
  885. case 25:
  886. #line 325 "./expread.y"
  887. { write_exp_elt_opcode (UNOP_CAST);
  888.               write_exp_elt_type (yyvsp[-2].tval);
  889.               write_exp_elt_opcode (UNOP_CAST); ;
  890.     break;}
  891. case 26:
  892. #line 331 "./expread.y"
  893. { ;
  894.     break;}
  895. case 27:
  896. #line 337 "./expread.y"
  897. { write_exp_elt_opcode (BINOP_REPEAT); ;
  898.     break;}
  899. case 28:
  900. #line 341 "./expread.y"
  901. { write_exp_elt_opcode (BINOP_MUL); ;
  902.     break;}
  903. case 29:
  904. #line 345 "./expread.y"
  905. { write_exp_elt_opcode (BINOP_DIV); ;
  906.     break;}
  907. case 30:
  908. #line 349 "./expread.y"
  909. { write_exp_elt_opcode (BINOP_REM); ;
  910.     break;}
  911. case 31:
  912. #line 353 "./expread.y"
  913. { write_exp_elt_opcode (BINOP_ADD); ;
  914.     break;}
  915. case 32:
  916. #line 357 "./expread.y"
  917. { write_exp_elt_opcode (BINOP_SUB); ;
  918.     break;}
  919. case 33:
  920. #line 361 "./expread.y"
  921. { write_exp_elt_opcode (BINOP_LSH); ;
  922.     break;}
  923. case 34:
  924. #line 365 "./expread.y"
  925. { write_exp_elt_opcode (BINOP_RSH); ;
  926.     break;}
  927. case 35:
  928. #line 369 "./expread.y"
  929. { write_exp_elt_opcode (BINOP_EQUAL); ;
  930.     break;}
  931. case 36:
  932. #line 373 "./expread.y"
  933. { write_exp_elt_opcode (BINOP_NOTEQUAL); ;
  934.     break;}
  935. case 37:
  936. #line 377 "./expread.y"
  937. { write_exp_elt_opcode (BINOP_LEQ); ;
  938.     break;}
  939. case 38:
  940. #line 381 "./expread.y"
  941. { write_exp_elt_opcode (BINOP_GEQ); ;
  942.     break;}
  943. case 39:
  944. #line 385 "./expread.y"
  945. { write_exp_elt_opcode (BINOP_LESS); ;
  946.     break;}
  947. case 40:
  948. #line 389 "./expread.y"
  949. { write_exp_elt_opcode (BINOP_GTR); ;
  950.     break;}
  951. case 41:
  952. #line 393 "./expread.y"
  953. { write_exp_elt_opcode (BINOP_LOGAND); ;
  954.     break;}
  955. case 42:
  956. #line 397 "./expread.y"
  957. { write_exp_elt_opcode (BINOP_LOGXOR); ;
  958.     break;}
  959. case 43:
  960. #line 401 "./expread.y"
  961. { write_exp_elt_opcode (BINOP_LOGIOR); ;
  962.     break;}
  963. case 44:
  964. #line 405 "./expread.y"
  965. { write_exp_elt_opcode (BINOP_AND); ;
  966.     break;}
  967. case 45:
  968. #line 409 "./expread.y"
  969. { write_exp_elt_opcode (BINOP_OR); ;
  970.     break;}
  971. case 46:
  972. #line 413 "./expread.y"
  973. { write_exp_elt_opcode (TERNOP_COND); ;
  974.     break;}
  975. case 47:
  976. #line 417 "./expread.y"
  977. { write_exp_elt_opcode (BINOP_ASSIGN); ;
  978.     break;}
  979. case 48:
  980. #line 421 "./expread.y"
  981. { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
  982.               write_exp_elt_opcode (yyvsp[-1].opcode);
  983.               write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); ;
  984.     break;}
  985. case 49:
  986. #line 427 "./expread.y"
  987. { write_exp_elt_opcode (OP_LONG);
  988.               if (yyvsp[0].lval == (int) yyvsp[0].lval || yyvsp[0].lval == (unsigned int) yyvsp[0].lval)
  989.                 write_exp_elt_type (builtin_type_int);
  990.               else
  991.                 write_exp_elt_type (BUILTIN_TYPE_LONGEST);
  992.               write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
  993.               write_exp_elt_opcode (OP_LONG); ;
  994.     break;}
  995. case 50:
  996. #line 437 "./expread.y"
  997. { YYSTYPE val;
  998.               parse_number (yyvsp[0].ssym.stoken.ptr, yyvsp[0].ssym.stoken.length, 0, &val);
  999.               write_exp_elt_opcode (OP_LONG);
  1000.               if (val.lval == (int) val.lval ||
  1001.                   val.lval == (unsigned int) val.lval)
  1002.                 write_exp_elt_type (builtin_type_int);
  1003.               else
  1004.                 write_exp_elt_type (BUILTIN_TYPE_LONGEST);
  1005.               write_exp_elt_longcst (val.lval);
  1006.               write_exp_elt_opcode (OP_LONG); ;
  1007.     break;}
  1008. case 51:
  1009. #line 450 "./expread.y"
  1010. {
  1011.               write_exp_elt_opcode (OP_LONG);
  1012.               if (yyvsp[0].ulval == (unsigned int) yyvsp[0].ulval)
  1013.                 write_exp_elt_type (builtin_type_unsigned_int);
  1014.               else
  1015.                 write_exp_elt_type (BUILTIN_TYPE_UNSIGNED_LONGEST);
  1016.               write_exp_elt_longcst ((LONGEST) yyvsp[0].ulval);
  1017.               write_exp_elt_opcode (OP_LONG);
  1018.             ;
  1019.     break;}
  1020. case 52:
  1021. #line 462 "./expread.y"
  1022. { YYSTYPE val;
  1023.               parse_number (yyvsp[0].ssym.stoken.ptr, yyvsp[0].ssym.stoken.length, 0, &val);
  1024.               write_exp_elt_opcode (OP_LONG);
  1025.               if (val.ulval == (unsigned int) val.ulval)
  1026.                 write_exp_elt_type (builtin_type_unsigned_int);
  1027.               else
  1028.                 write_exp_elt_type (BUILTIN_TYPE_UNSIGNED_LONGEST);
  1029.               write_exp_elt_longcst ((LONGEST)val.ulval);
  1030.               write_exp_elt_opcode (OP_LONG);
  1031.             ;
  1032.     break;}
  1033. case 53:
  1034. #line 475 "./expread.y"
  1035. { write_exp_elt_opcode (OP_LONG);
  1036.               write_exp_elt_type (builtin_type_char);
  1037.               write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
  1038.               write_exp_elt_opcode (OP_LONG); ;
  1039.     break;}
  1040. case 54:
  1041. #line 482 "./expread.y"
  1042. { write_exp_elt_opcode (OP_DOUBLE);
  1043.               write_exp_elt_type (builtin_type_double);
  1044.               write_exp_elt_dblcst (yyvsp[0].dval);
  1045.               write_exp_elt_opcode (OP_DOUBLE); ;
  1046.     break;}
  1047. case 56:
  1048. #line 492 "./expread.y"
  1049. { write_exp_elt_opcode (OP_LAST);
  1050.               write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
  1051.               write_exp_elt_opcode (OP_LAST); ;
  1052.     break;}
  1053. case 57:
  1054. #line 498 "./expread.y"
  1055. { write_exp_elt_opcode (OP_REGISTER);
  1056.               write_exp_elt_longcst ((LONGEST) yyvsp[0].lval);
  1057.               write_exp_elt_opcode (OP_REGISTER); ;
  1058.     break;}
  1059. case 58:
  1060. #line 504 "./expread.y"
  1061. { write_exp_elt_opcode (OP_INTERNALVAR);
  1062.               write_exp_elt_intern (yyvsp[0].ivar);
  1063.               write_exp_elt_opcode (OP_INTERNALVAR); ;
  1064.     break;}
  1065. case 59:
  1066. #line 510 "./expread.y"
  1067. { write_exp_elt_opcode (OP_LONG);
  1068.               write_exp_elt_type (builtin_type_int);
  1069.               write_exp_elt_longcst ((LONGEST) TYPE_LENGTH (yyvsp[-1].tval));
  1070.               write_exp_elt_opcode (OP_LONG); ;
  1071.     break;}
  1072. case 60:
  1073. #line 517 "./expread.y"
  1074. { write_exp_elt_opcode (OP_STRING);
  1075.               write_exp_string (yyvsp[0].sval);
  1076.               write_exp_elt_opcode (OP_STRING); ;
  1077.     break;}
  1078. case 61:
  1079. #line 524 "./expread.y"
  1080. { write_exp_elt_opcode (OP_THIS);
  1081.               write_exp_elt_opcode (OP_THIS); ;
  1082.     break;}
  1083. case 62:
  1084. #line 531 "./expread.y"
  1085. {
  1086.               if (yyvsp[0].ssym.sym != 0)
  1087.                   yyval.bval = SYMBOL_BLOCK_VALUE (yyvsp[0].ssym.sym);
  1088.               else
  1089.                 {
  1090.                   struct symtab *tem =
  1091.                   lookup_symtab (copy_name (yyvsp[0].ssym.stoken));
  1092.                   if (tem)
  1093.                 yyval.bval = BLOCKVECTOR_BLOCK
  1094.                      (BLOCKVECTOR (tem), STATIC_BLOCK);
  1095.                   else
  1096.                 error ("No file or function \"%s\".",
  1097.                        copy_name (yyvsp[0].ssym.stoken));
  1098.                 }
  1099.             ;
  1100.     break;}
  1101. case 63:
  1102. #line 549 "./expread.y"
  1103. { struct symbol *tem
  1104.                 = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval,
  1105.                          VAR_NAMESPACE, 0, NULL);
  1106.               if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  1107.                 error ("No function \"%s\" in specified context.",
  1108.                    copy_name (yyvsp[0].sval));
  1109.               yyval.bval = SYMBOL_BLOCK_VALUE (tem); ;
  1110.     break;}
  1111. case 64:
  1112. #line 559 "./expread.y"
  1113. { struct symbol *sym;
  1114.               sym = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval,
  1115.                            VAR_NAMESPACE, 0, NULL);
  1116.               if (sym == 0)
  1117.                 error ("No symbol \"%s\" in specified context.",
  1118.                    copy_name (yyvsp[0].sval));
  1119.               write_exp_elt_opcode (OP_VAR_VALUE);
  1120.               write_exp_elt_sym (sym);
  1121.               write_exp_elt_opcode (OP_VAR_VALUE); ;
  1122.     break;}
  1123. case 65:
  1124. #line 571 "./expread.y"
  1125. {
  1126.               struct type *type = yyvsp[-2].tval;
  1127.               if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  1128.                   && TYPE_CODE (type) != TYPE_CODE_UNION)
  1129.                 error ("`%s' is not defined as an aggregate type.",
  1130.                    TYPE_NAME (type));
  1131.  
  1132.               write_exp_elt_opcode (OP_SCOPE);
  1133.               write_exp_elt_type (type);
  1134.               write_exp_string (yyvsp[0].sval);
  1135.               write_exp_elt_opcode (OP_SCOPE);
  1136.             ;
  1137.     break;}
  1138. case 66:
  1139. #line 584 "./expread.y"
  1140. {
  1141.               struct type *type = yyvsp[-3].tval;
  1142.               if (TYPE_CODE (type) != TYPE_CODE_STRUCT
  1143.                   && TYPE_CODE (type) != TYPE_CODE_UNION)
  1144.                 error ("`%s' is not defined as an aggregate type.",
  1145.                    TYPE_NAME (type));
  1146.  
  1147.               if (strcmp (type_name_no_tag (type), yyvsp[0].sval.ptr))
  1148.                 error ("invalid destructor `%s::~%s'",
  1149.                    type_name_no_tag (type), yyvsp[0].sval.ptr);
  1150.  
  1151.               write_exp_elt_opcode (OP_SCOPE);
  1152.               write_exp_elt_type (type);
  1153.               write_exp_string (yyvsp[0].sval);
  1154.               write_exp_elt_opcode (OP_SCOPE);
  1155.               write_exp_elt_opcode (UNOP_LOGNOT);
  1156.             ;
  1157.     break;}
  1158. case 67:
  1159. #line 602 "./expread.y"
  1160. {
  1161.               char *name = copy_name (yyvsp[0].sval);
  1162.               struct symbol *sym;
  1163.               int i;
  1164.  
  1165.               sym =
  1166.                 lookup_symbol (name, 0, VAR_NAMESPACE, 0, NULL);
  1167.               if (sym)
  1168.                 {
  1169.                   write_exp_elt_opcode (OP_VAR_VALUE);
  1170.                   write_exp_elt_sym (sym);
  1171.                   write_exp_elt_opcode (OP_VAR_VALUE);
  1172.                   break;
  1173.                 }
  1174.               for (i = 0; i < misc_function_count; i++)
  1175.                 if (!strcmp (misc_function_vector[i].name, name))
  1176.                   break;
  1177.  
  1178.               if (i < misc_function_count)
  1179.                 {
  1180.                   enum misc_function_type mft =
  1181.                   misc_function_vector[i].type;
  1182.                   
  1183.                   write_exp_elt_opcode (OP_LONG);
  1184.                   write_exp_elt_type (builtin_type_int);
  1185.                   write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address);
  1186.                   write_exp_elt_opcode (OP_LONG);
  1187.                   write_exp_elt_opcode (UNOP_MEMVAL);
  1188.                   if (mft == mf_data || mft == mf_bss)
  1189.                 write_exp_elt_type (builtin_type_int);
  1190.                   else if (mft == mf_text)
  1191.                 write_exp_elt_type (lookup_function_type (builtin_type_int));
  1192.                   else
  1193.                 write_exp_elt_type (builtin_type_char);
  1194.                   write_exp_elt_opcode (UNOP_MEMVAL);
  1195.                 }
  1196.               else
  1197.                 if (symtab_list == 0
  1198.                 && partial_symtab_list == 0)
  1199.                   error ("No symbol table is loaded.  Use the \"file\" command.");
  1200.                 else
  1201.                   error ("No symbol \"%s\" in current context.", name);
  1202.             ;
  1203.     break;}
  1204. case 68:
  1205. #line 648 "./expread.y"
  1206. { struct symbol *sym = yyvsp[0].ssym.sym;
  1207.  
  1208.               if (sym)
  1209.                 {
  1210.                   switch (sym->class)
  1211.                 {
  1212.                 case LOC_REGISTER:
  1213.                 case LOC_ARG:
  1214.                 case LOC_REF_ARG:
  1215.                 case LOC_REGPARM:
  1216.                 case LOC_LOCAL:
  1217.                 case LOC_LOCAL_ARG:
  1218.                   if (innermost_block == 0 ||
  1219.                       contained_in (block_found, 
  1220.                             innermost_block))
  1221.                     innermost_block = block_found;
  1222.                 case LOC_UNDEF:
  1223.                 case LOC_CONST:
  1224.                 case LOC_STATIC:
  1225.                 case LOC_TYPEDEF:
  1226.                 case LOC_LABEL:
  1227.                 case LOC_BLOCK:
  1228.                 case LOC_CONST_BYTES:
  1229.  
  1230.                   /* In this case the expression can
  1231.                      be evaluated regardless of what
  1232.                      frame we are in, so there is no
  1233.                      need to check for the
  1234.                      innermost_block.  These cases are
  1235.                      listed so that gcc -Wall will
  1236.                      report types that may not have
  1237.                      been considered.  */
  1238.  
  1239.                   break;
  1240.                 }
  1241.                   write_exp_elt_opcode (OP_VAR_VALUE);
  1242.                   write_exp_elt_sym (sym);
  1243.                   write_exp_elt_opcode (OP_VAR_VALUE);
  1244.                 }
  1245.               else if (yyvsp[0].ssym.is_a_field_of_this)
  1246.                 {
  1247.                   /* C++: it hangs off of `this'.  Must
  1248.                      not inadvertently convert from a method call
  1249.                  to data ref.  */
  1250.                   if (innermost_block == 0 || 
  1251.                   contained_in (block_found, innermost_block))
  1252.                 innermost_block = block_found;
  1253.                   write_exp_elt_opcode (OP_THIS);
  1254.                   write_exp_elt_opcode (OP_THIS);
  1255.                   write_exp_elt_opcode (STRUCTOP_PTR);
  1256.                   write_exp_string (yyvsp[0].ssym.stoken);
  1257.                   write_exp_elt_opcode (STRUCTOP_PTR);
  1258.                 }
  1259.               else
  1260.                 {
  1261.                   register int i;
  1262.                   register char *arg = copy_name (yyvsp[0].ssym.stoken);
  1263.  
  1264.                 /* FIXME, this search is linear!  At least
  1265.                    optimize the strcmp with a 1-char cmp... */
  1266.                   for (i = 0; i < misc_function_count; i++)
  1267.                 if (!strcmp (misc_function_vector[i].name, arg))
  1268.                   break;
  1269.  
  1270.                   if (i < misc_function_count)
  1271.                 {
  1272.                   enum misc_function_type mft =
  1273.                       misc_function_vector[i].type;
  1274.                   
  1275.                   write_exp_elt_opcode (OP_LONG);
  1276.                   write_exp_elt_type (builtin_type_int);
  1277.                   write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address);
  1278.                   write_exp_elt_opcode (OP_LONG);
  1279.                   write_exp_elt_opcode (UNOP_MEMVAL);
  1280.                   if (mft == mf_data || mft == mf_bss)
  1281.                     write_exp_elt_type (builtin_type_int);
  1282.                   else if (mft == mf_text)
  1283.                     write_exp_elt_type (lookup_function_type (builtin_type_int));
  1284.                   else
  1285.                     write_exp_elt_type (builtin_type_char);
  1286.                   write_exp_elt_opcode (UNOP_MEMVAL);
  1287.                 }
  1288.                   else if (symtab_list == 0
  1289.                        && partial_symtab_list == 0)
  1290.                 error ("No symbol table is loaded.  Use the \"file\" command.");
  1291.                   else
  1292.                 error ("No symbol \"%s\" in current context.",
  1293.                        copy_name (yyvsp[0].ssym.stoken));
  1294.                 }
  1295.             ;
  1296.     break;}
  1297. case 70:
  1298. #line 743 "./expread.y"
  1299. {
  1300.           /* This is where the interesting stuff happens.  */
  1301.           int done = 0;
  1302.           int array_size;
  1303.           struct type *follow_type = yyvsp[-1].tval;
  1304.           
  1305.           while (!done)
  1306.             switch (pop_type ())
  1307.               {
  1308.               case tp_end:
  1309.             done = 1;
  1310.             break;
  1311.               case tp_pointer:
  1312.             follow_type = lookup_pointer_type (follow_type);
  1313.             break;
  1314.               case tp_reference:
  1315.             follow_type = lookup_reference_type (follow_type);
  1316.             break;
  1317.               case tp_array:
  1318.             array_size = pop_type_int ();
  1319.             if (array_size != -1)
  1320.               follow_type = create_array_type (follow_type,
  1321.                                array_size);
  1322.             else
  1323.               follow_type = lookup_pointer_type (follow_type);
  1324.             break;
  1325.               case tp_function:
  1326.             follow_type = lookup_function_type (follow_type);
  1327.             break;
  1328.               }
  1329.           yyval.tval = follow_type;
  1330.         ;
  1331.     break;}
  1332. case 71:
  1333. #line 778 "./expread.y"
  1334. { push_type (tp_pointer); yyval.voidval = 0; ;
  1335.     break;}
  1336. case 72:
  1337. #line 780 "./expread.y"
  1338. { push_type (tp_pointer); yyval.voidval = yyvsp[0].voidval; ;
  1339.     break;}
  1340. case 73:
  1341. #line 782 "./expread.y"
  1342. { push_type (tp_reference); yyval.voidval = 0; ;
  1343.     break;}
  1344. case 74:
  1345. #line 784 "./expread.y"
  1346. { push_type (tp_reference); yyval.voidval = yyvsp[0].voidval; ;
  1347.     break;}
  1348. case 76:
  1349. #line 789 "./expread.y"
  1350. { yyval.voidval = yyvsp[-1].voidval; ;
  1351.     break;}
  1352. case 77:
  1353. #line 791 "./expread.y"
  1354. {
  1355.               push_type_int (yyvsp[0].lval);
  1356.               push_type (tp_array);
  1357.             ;
  1358.     break;}
  1359. case 78:
  1360. #line 796 "./expread.y"
  1361. {
  1362.               push_type_int (yyvsp[0].lval);
  1363.               push_type (tp_array);
  1364.               yyval.voidval = 0;
  1365.             ;
  1366.     break;}
  1367. case 79:
  1368. #line 802 "./expread.y"
  1369. { push_type (tp_function); ;
  1370.     break;}
  1371. case 80:
  1372. #line 804 "./expread.y"
  1373. { push_type (tp_function); ;
  1374.     break;}
  1375. case 81:
  1376. #line 808 "./expread.y"
  1377. { yyval.lval = -1; ;
  1378.     break;}
  1379. case 82:
  1380. #line 810 "./expread.y"
  1381. { yyval.lval = yyvsp[-1].lval; ;
  1382.     break;}
  1383. case 83:
  1384. #line 814 "./expread.y"
  1385. { yyval.voidval = 0; ;
  1386.     break;}
  1387. case 85:
  1388. #line 819 "./expread.y"
  1389. { yyval.tval = lookup_member_type (builtin_type_int, yyvsp[-2].tval); ;
  1390.     break;}
  1391. case 86:
  1392. #line 821 "./expread.y"
  1393. { yyval.tval = lookup_member_type (yyvsp[-5].tval, yyvsp[-3].tval); ;
  1394.     break;}
  1395. case 87:
  1396. #line 823 "./expread.y"
  1397. { yyval.tval = lookup_member_type
  1398.                 (lookup_function_type (yyvsp[-7].tval), yyvsp[-5].tval); ;
  1399.     break;}
  1400. case 88:
  1401. #line 826 "./expread.y"
  1402. { yyval.tval = lookup_member_type
  1403.                 (lookup_function_type (yyvsp[-8].tval), yyvsp[-6].tval);
  1404.               free (yyvsp[-1].tvec); ;
  1405.     break;}
  1406. case 89:
  1407. #line 833 "./expread.y"
  1408. { yyval.tval = yyvsp[0].tsym.type; ;
  1409.     break;}
  1410. case 90:
  1411. #line 835 "./expread.y"
  1412. { yyval.tval = builtin_type_int; ;
  1413.     break;}
  1414. case 91:
  1415. #line 837 "./expread.y"
  1416. { yyval.tval = builtin_type_long; ;
  1417.     break;}
  1418. case 92:
  1419. #line 839 "./expread.y"
  1420. { yyval.tval = builtin_type_short; ;
  1421.     break;}
  1422. case 93:
  1423. #line 841 "./expread.y"
  1424. { yyval.tval = builtin_type_long; ;
  1425.     break;}
  1426. case 94:
  1427. #line 843 "./expread.y"
  1428. { yyval.tval = builtin_type_unsigned_long; ;
  1429.     break;}
  1430. case 95:
  1431. #line 845 "./expread.y"
  1432. { yyval.tval = builtin_type_long_long; ;
  1433.     break;}
  1434. case 96:
  1435. #line 847 "./expread.y"
  1436. { yyval.tval = builtin_type_long_long; ;
  1437.     break;}
  1438. case 97:
  1439. #line 849 "./expread.y"
  1440. { yyval.tval = builtin_type_unsigned_long_long; ;
  1441.     break;}
  1442. case 98:
  1443. #line 851 "./expread.y"
  1444. { yyval.tval = builtin_type_unsigned_long_long; ;
  1445.     break;}
  1446. case 99:
  1447. #line 853 "./expread.y"
  1448. { yyval.tval = builtin_type_short; ;
  1449.     break;}
  1450. case 100:
  1451. #line 855 "./expread.y"
  1452. { yyval.tval = builtin_type_unsigned_short; ;
  1453.     break;}
  1454. case 101:
  1455. #line 857 "./expread.y"
  1456. { yyval.tval = lookup_struct (copy_name (yyvsp[0].sval),
  1457.                           expression_context_block); ;
  1458.     break;}
  1459. case 102:
  1460. #line 860 "./expread.y"
  1461. { yyval.tval = lookup_union (copy_name (yyvsp[0].sval),
  1462.                          expression_context_block); ;
  1463.     break;}
  1464. case 103:
  1465. #line 863 "./expread.y"
  1466. { yyval.tval = lookup_enum (copy_name (yyvsp[0].sval),
  1467.                         expression_context_block); ;
  1468.     break;}
  1469. case 104:
  1470. #line 866 "./expread.y"
  1471. { yyval.tval = lookup_unsigned_typename (TYPE_NAME(yyvsp[0].tsym.type)); ;
  1472.     break;}
  1473. case 105:
  1474. #line 868 "./expread.y"
  1475. { yyval.tval = builtin_type_unsigned_int; ;
  1476.     break;}
  1477. case 106:
  1478. #line 870 "./expread.y"
  1479. { yyval.tval = yyvsp[0].tsym.type; ;
  1480.     break;}
  1481. case 107:
  1482. #line 872 "./expread.y"
  1483. { yyval.tval = builtin_type_int; ;
  1484.     break;}
  1485. case 109:
  1486. #line 877 "./expread.y"
  1487. {
  1488.           yyval.tsym.stoken.ptr = "int";
  1489.           yyval.tsym.stoken.length = 3;
  1490.           yyval.tsym.type = builtin_type_int;
  1491.         ;
  1492.     break;}
  1493. case 110:
  1494. #line 883 "./expread.y"
  1495. {
  1496.           yyval.tsym.stoken.ptr = "long";
  1497.           yyval.tsym.stoken.length = 4;
  1498.           yyval.tsym.type = builtin_type_long;
  1499.         ;
  1500.     break;}
  1501. case 111:
  1502. #line 889 "./expread.y"
  1503. {
  1504.           yyval.tsym.stoken.ptr = "short";
  1505.           yyval.tsym.stoken.length = 5;
  1506.           yyval.tsym.type = builtin_type_short;
  1507.         ;
  1508.     break;}
  1509. case 112:
  1510. #line 898 "./expread.y"
  1511. { yyval.tvec = (struct type **)xmalloc (sizeof (struct type *) * 2);
  1512.           yyval.tvec[0] = (struct type *)0;
  1513.           yyval.tvec[1] = yyvsp[0].tval;
  1514.         ;
  1515.     break;}
  1516. case 113:
  1517. #line 903 "./expread.y"
  1518. { int len = sizeof (struct type *) * ++(yyvsp[-2].ivec[0]);
  1519.           yyval.tvec = (struct type **)xrealloc (yyvsp[-2].tvec, len);
  1520.           yyval.tvec[yyval.ivec[0]] = yyvsp[0].tval;
  1521.         ;
  1522.     break;}
  1523. case 114:
  1524. #line 909 "./expread.y"
  1525. { yyval.sval = yyvsp[0].ssym.stoken; ;
  1526.     break;}
  1527. case 115:
  1528. #line 910 "./expread.y"
  1529. { yyval.sval = yyvsp[0].ssym.stoken; ;
  1530.     break;}
  1531. case 116:
  1532. #line 911 "./expread.y"
  1533. { yyval.sval = yyvsp[0].tsym.stoken; ;
  1534.     break;}
  1535. case 117:
  1536. #line 912 "./expread.y"
  1537. { yyval.sval = yyvsp[0].ssym.stoken; ;
  1538.     break;}
  1539. case 118:
  1540. #line 913 "./expread.y"
  1541. { yyval.sval = yyvsp[0].ssym.stoken; ;
  1542.     break;}
  1543. }
  1544.    /* the action file gets copied in in place of this dollarsign */
  1545. #line 327 "bison.simple"
  1546.  
  1547.   yyvsp -= yylen;
  1548.   yyssp -= yylen;
  1549. #ifdef YYLSP_NEEDED
  1550.   yylsp -= yylen;
  1551. #endif
  1552.  
  1553. #if YYDEBUG != 0
  1554.   if (yydebug)
  1555.     {
  1556.       short *ssp1 = yyss - 1;
  1557.       fprintf (stderr, "state stack now");
  1558.       while (ssp1 != yyssp)
  1559.     fprintf (stderr, " %d", *++ssp1);
  1560.       fprintf (stderr, "\n");
  1561.     }
  1562. #endif
  1563.  
  1564.   *++yyvsp = yyval;
  1565.  
  1566. #ifdef YYLSP_NEEDED
  1567.   yylsp++;
  1568.   if (yylen == 0)
  1569.     {
  1570.       yylsp->first_line = yylloc.first_line;
  1571.       yylsp->first_column = yylloc.first_column;
  1572.       yylsp->last_line = (yylsp-1)->last_line;
  1573.       yylsp->last_column = (yylsp-1)->last_column;
  1574.       yylsp->text = 0;
  1575.     }
  1576.   else
  1577.     {
  1578.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1579.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1580.     }
  1581. #endif
  1582.  
  1583.   /* Now "shift" the result of the reduction.
  1584.      Determine what state that goes to,
  1585.      based on the state we popped back to
  1586.      and the rule number reduced by.  */
  1587.  
  1588.   yyn = yyr1[yyn];
  1589.  
  1590.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1591.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1592.     yystate = yytable[yystate];
  1593.   else
  1594.     yystate = yydefgoto[yyn - YYNTBASE];
  1595.  
  1596.   goto yynewstate;
  1597.  
  1598. yyerrlab:   /* here on detecting error */
  1599.  
  1600.   if (! yyerrstatus)
  1601.     /* If not already recovering from an error, report this error.  */
  1602.     {
  1603.       ++yynerrs;
  1604.       yyerror("parse error");
  1605.     }
  1606.  
  1607.   if (yyerrstatus == 3)
  1608.     {
  1609.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1610.  
  1611.       /* return failure if at end of input */
  1612.       if (yychar == YYEOF)
  1613.     YYABORT;
  1614.  
  1615. #if YYDEBUG != 0
  1616.       if (yydebug)
  1617.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1618. #endif
  1619.  
  1620.       yychar = YYEMPTY;
  1621.     }
  1622.  
  1623.   /* Else will try to reuse lookahead token
  1624.      after shifting the error token.  */
  1625.  
  1626.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1627.  
  1628.   goto yyerrhandle;
  1629.  
  1630. yyerrdefault:  /* current state does not do anything special for the error token. */
  1631.  
  1632. #if 0
  1633.   /* This is wrong; only states that explicitly want error tokens
  1634.      should shift them.  */
  1635.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1636.   if (yyn) goto yydefault;
  1637. #endif
  1638.  
  1639. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1640.  
  1641.   if (yyssp == yyss) YYABORT;
  1642.   yyvsp--;
  1643.   yystate = *--yyssp;
  1644. #ifdef YYLSP_NEEDED
  1645.   yylsp--;
  1646. #endif
  1647.  
  1648. #if YYDEBUG != 0
  1649.   if (yydebug)
  1650.     {
  1651.       short *ssp1 = yyss - 1;
  1652.       fprintf (stderr, "Error: state stack now");
  1653.       while (ssp1 != yyssp)
  1654.     fprintf (stderr, " %d", *++ssp1);
  1655.       fprintf (stderr, "\n");
  1656.     }
  1657. #endif
  1658.  
  1659. yyerrhandle:
  1660.  
  1661.   yyn = yypact[yystate];
  1662.   if (yyn == YYFLAG)
  1663.     goto yyerrdefault;
  1664.  
  1665.   yyn += YYTERROR;
  1666.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1667.     goto yyerrdefault;
  1668.  
  1669.   yyn = yytable[yyn];
  1670.   if (yyn < 0)
  1671.     {
  1672.       if (yyn == YYFLAG)
  1673.     goto yyerrpop;
  1674.       yyn = -yyn;
  1675.       goto yyreduce;
  1676.     }
  1677.   else if (yyn == 0)
  1678.     goto yyerrpop;
  1679.  
  1680.   if (yyn == YYFINAL)
  1681.     YYACCEPT;
  1682.  
  1683. #if YYDEBUG != 0
  1684.   if (yydebug)
  1685.     fprintf(stderr, "Shifting error token, ");
  1686. #endif
  1687.  
  1688.   *++yyvsp = yylval;
  1689. #ifdef YYLSP_NEEDED
  1690.   *++yylsp = yylloc;
  1691. #endif
  1692.  
  1693.   yystate = yyn;
  1694.   goto yynewstate;
  1695. }
  1696. #line 928 "./expread.y"
  1697.  
  1698.  
  1699. /* Begin counting arguments for a function call,
  1700.    saving the data about any containing call.  */
  1701.  
  1702. static void
  1703. start_arglist ()
  1704. {
  1705.   register struct funcall *new = (struct funcall *) xmalloc (sizeof (struct funcall));
  1706.  
  1707.   new->next = funcall_chain;
  1708.   new->arglist_len = arglist_len;
  1709.   arglist_len = 0;
  1710.   funcall_chain = new;
  1711. }
  1712.  
  1713. /* Return the number of arguments in a function call just terminated,
  1714.    and restore the data for the containing function call.  */
  1715.  
  1716. static int
  1717. end_arglist ()
  1718. {
  1719.   register int val = arglist_len;
  1720.   register struct funcall *call = funcall_chain;
  1721.   funcall_chain = call->next;
  1722.   arglist_len = call->arglist_len;
  1723.   free (call);
  1724.   return val;
  1725. }
  1726.  
  1727. /* Free everything in the funcall chain.
  1728.    Used when there is an error inside parsing.  */
  1729.  
  1730. static void
  1731. free_funcalls ()
  1732. {
  1733.   register struct funcall *call, *next;
  1734.  
  1735.   for (call = funcall_chain; call; call = next)
  1736.     {
  1737.       next = call->next;
  1738.       free (call);
  1739.     }
  1740. }
  1741.  
  1742. /* This page contains the functions for adding data to the  struct expression
  1743.    being constructed.  */
  1744.  
  1745. /* Add one element to the end of the expression.  */
  1746.  
  1747. /* To avoid a bug in the Sun 4 compiler, we pass things that can fit into
  1748.    a register through here */
  1749.  
  1750. static void
  1751. write_exp_elt (expelt)
  1752.      union exp_element expelt;
  1753. {
  1754.   if (expout_ptr >= expout_size)
  1755.     {
  1756.       expout_size *= 2;
  1757.       expout = (struct expression *) xrealloc (expout,
  1758.                            sizeof (struct expression)
  1759.                            + expout_size * sizeof (union exp_element));
  1760.     }
  1761.   expout->elts[expout_ptr++] = expelt;
  1762. }
  1763.  
  1764. static void
  1765. write_exp_elt_opcode (expelt)
  1766.      enum exp_opcode expelt;
  1767. {
  1768.   union exp_element tmp;
  1769.  
  1770.   tmp.opcode = expelt;
  1771.  
  1772.   write_exp_elt (tmp);
  1773. }
  1774.  
  1775. static void
  1776. write_exp_elt_sym (expelt)
  1777.      struct symbol *expelt;
  1778. {
  1779.   union exp_element tmp;
  1780.  
  1781.   tmp.symbol = expelt;
  1782.  
  1783.   write_exp_elt (tmp);
  1784. }
  1785.  
  1786. static void
  1787. write_exp_elt_longcst (expelt)
  1788.      LONGEST expelt;
  1789. {
  1790.   union exp_element tmp;
  1791.  
  1792.   tmp.longconst = expelt;
  1793.  
  1794.   write_exp_elt (tmp);
  1795. }
  1796.  
  1797. static void
  1798. write_exp_elt_dblcst (expelt)
  1799.      double expelt;
  1800. {
  1801.   union exp_element tmp;
  1802.  
  1803.   tmp.doubleconst = expelt;
  1804.  
  1805.   write_exp_elt (tmp);
  1806. }
  1807.  
  1808. static void
  1809. write_exp_elt_type (expelt)
  1810.      struct type *expelt;
  1811. {
  1812.   union exp_element tmp;
  1813.  
  1814.   tmp.type = expelt;
  1815.  
  1816.   write_exp_elt (tmp);
  1817. }
  1818.  
  1819. static void
  1820. write_exp_elt_intern (expelt)
  1821.      struct internalvar *expelt;
  1822. {
  1823.   union exp_element tmp;
  1824.  
  1825.   tmp.internalvar = expelt;
  1826.  
  1827.   write_exp_elt (tmp);
  1828. }
  1829.  
  1830. /* Add a string constant to the end of the expression.
  1831.    Follow it by its length in bytes, as a separate exp_element.  */
  1832.  
  1833. static void
  1834. write_exp_string (str)
  1835.      struct stoken str;
  1836. {
  1837.   register int len = str.length;
  1838.   register int lenelt
  1839.     = (len + sizeof (union exp_element)) / sizeof (union exp_element);
  1840.  
  1841.   expout_ptr += lenelt;
  1842.  
  1843.   if (expout_ptr >= expout_size)
  1844.     {
  1845.       expout_size = max (expout_size * 2, expout_ptr + 10);
  1846.       expout = (struct expression *)
  1847.     xrealloc (expout, (sizeof (struct expression)
  1848.                + (expout_size * sizeof (union exp_element))));
  1849.     }
  1850.   bcopy (str.ptr, (char *) &expout->elts[expout_ptr - lenelt], len);
  1851.   ((char *) &expout->elts[expout_ptr - lenelt])[len] = 0;
  1852.   write_exp_elt_longcst ((LONGEST) len);
  1853. }
  1854.  
  1855. /* During parsing of a C expression, the pointer to the next character
  1856.    is in this variable.  */
  1857.  
  1858. static char *lexptr;
  1859.  
  1860. /* Tokens that refer to names do so with explicit pointer and length,
  1861.    so they can share the storage that lexptr is parsing.
  1862.  
  1863.    When it is necessary to pass a name to a function that expects
  1864.    a null-terminated string, the substring is copied out
  1865.    into a block of storage that namecopy points to.
  1866.  
  1867.    namecopy is allocated once, guaranteed big enough, for each parsing.  */
  1868.  
  1869. static char *namecopy;
  1870.  
  1871. /* Current depth in parentheses within the expression.  */
  1872.  
  1873. static int paren_depth;
  1874.  
  1875. /* Nonzero means stop parsing on first comma (if not within parentheses).  */
  1876.  
  1877. static int comma_terminates;
  1878.  
  1879. /* Take care of parsing a number (anything that starts with a digit).
  1880.    Set yylval and return the token type; update lexptr.
  1881.    LEN is the number of characters in it.  */
  1882.  
  1883. /*** Needs some error checking for the float case ***/
  1884.  
  1885. static int
  1886. parse_number (p, len, parsed_float, putithere)
  1887.      register char *p;
  1888.      register int len;
  1889.      int parsed_float;
  1890.      YYSTYPE *putithere;
  1891. {
  1892.   register LONGEST n = 0;
  1893.   register int i;
  1894.   register int c;
  1895.   register int base = input_radix;
  1896.   int unsigned_p = 0;
  1897.  
  1898.   extern double atof ();
  1899.  
  1900.   if (parsed_float)
  1901.     {
  1902.       /* It's a float since it contains a point or an exponent.  */
  1903.       putithere->dval = atof (p);
  1904.       return FLOAT;
  1905.     }
  1906.  
  1907.   /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
  1908.   if (p[0] == '0')
  1909.     switch (p[1])
  1910.       {
  1911.       case 'x':
  1912.       case 'X':
  1913.     if (len >= 3)
  1914.       {
  1915.         p += 2;
  1916.         base = 16;
  1917.         len -= 2;
  1918.       }
  1919.     break;
  1920.  
  1921.       case 't':
  1922.       case 'T':
  1923.       case 'd':
  1924.       case 'D':
  1925.     if (len >= 3)
  1926.       {
  1927.         p += 2;
  1928.         base = 10;
  1929.         len -= 2;
  1930.       }
  1931.     break;
  1932.  
  1933.       default:
  1934.     base = 8;
  1935.     break;
  1936.       }
  1937.  
  1938.   while (len-- > 0)
  1939.     {
  1940.       c = *p++;
  1941.       if (c >= 'A' && c <= 'Z')
  1942.     c += 'a' - 'A';
  1943.       if (c != 'l' && c != 'u')
  1944.     n *= base;
  1945.       if (c >= '0' && c <= '9')
  1946.     n += i = c - '0';
  1947.       else
  1948.     {
  1949.       if (base > 10 && c >= 'a' && c <= 'f')
  1950.         n += i = c - 'a' + 10;
  1951.       else if (len == 0 && c == 'l')
  1952.         ;
  1953.       else if (len == 0 && c == 'u')
  1954.         unsigned_p = 1;
  1955.       else
  1956.         return ERROR;    /* Char not a digit */
  1957.     }
  1958.       if (i >= base)
  1959.     return ERROR;        /* Invalid digit in this base */
  1960.     }
  1961.  
  1962.   if (unsigned_p)
  1963.     {
  1964.       putithere->ulval = n;
  1965.       return UINT;
  1966.     }
  1967.   else
  1968.     {
  1969.       putithere->lval = n;
  1970.       return INT;
  1971.     }
  1972. }
  1973.  
  1974. struct token
  1975. {
  1976.   char *operator;
  1977.   int token;
  1978.   enum exp_opcode opcode;
  1979. };
  1980.  
  1981. const static struct token tokentab3[] =
  1982.   {
  1983.     {">>=", ASSIGN_MODIFY, BINOP_RSH},
  1984.     {"<<=", ASSIGN_MODIFY, BINOP_LSH}
  1985.   };
  1986.  
  1987. const static struct token tokentab2[] =
  1988.   {
  1989.     {"+=", ASSIGN_MODIFY, BINOP_ADD},
  1990.     {"-=", ASSIGN_MODIFY, BINOP_SUB},
  1991.     {"*=", ASSIGN_MODIFY, BINOP_MUL},
  1992.     {"/=", ASSIGN_MODIFY, BINOP_DIV},
  1993.     {"%=", ASSIGN_MODIFY, BINOP_REM},
  1994.     {"|=", ASSIGN_MODIFY, BINOP_LOGIOR},
  1995.     {"&=", ASSIGN_MODIFY, BINOP_LOGAND},
  1996.     {"^=", ASSIGN_MODIFY, BINOP_LOGXOR},
  1997.     {"++", INCREMENT, BINOP_END},
  1998.     {"--", DECREMENT, BINOP_END},
  1999.     {"->", ARROW, BINOP_END},
  2000.     {"&&", AND, BINOP_END},
  2001.     {"||", OR, BINOP_END},
  2002.     {"::", COLONCOLON, BINOP_END},
  2003.     {"<<", LSH, BINOP_END},
  2004.     {">>", RSH, BINOP_END},
  2005.     {"==", EQUAL, BINOP_END},
  2006.     {"!=", NOTEQUAL, BINOP_END},
  2007.     {"<=", LEQ, BINOP_END},
  2008.     {">=", GEQ, BINOP_END}
  2009.   };
  2010.  
  2011. /* assign machine-independent names to certain registers 
  2012.  * (unless overridden by the REGISTER_NAMES table)
  2013.  */
  2014. struct std_regs {
  2015.     char *name;
  2016.     int regnum;
  2017. } std_regs[] = {
  2018. #ifdef PC_REGNUM
  2019.     { "pc", PC_REGNUM },
  2020. #endif
  2021. #ifdef FP_REGNUM
  2022.     { "fp", FP_REGNUM },
  2023. #endif
  2024. #ifdef SP_REGNUM
  2025.     { "sp", SP_REGNUM },
  2026. #endif
  2027. #ifdef PS_REGNUM
  2028.     { "ps", PS_REGNUM },
  2029. #endif
  2030. };
  2031.  
  2032. #define NUM_STD_REGS (sizeof std_regs / sizeof std_regs[0])
  2033.  
  2034. /* Read one token, getting characters through lexptr.  */
  2035.  
  2036. static int
  2037. yylex ()
  2038. {
  2039.   register int c;
  2040.   register int namelen;
  2041.   register unsigned i;
  2042.   register char *tokstart;
  2043.  
  2044.  retry:
  2045.  
  2046.   tokstart = lexptr;
  2047.   /* See if it is a special token of length 3.  */
  2048.   for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
  2049.     if (!strncmp (tokstart, tokentab3[i].operator, 3))
  2050.       {
  2051.     lexptr += 3;
  2052.     yylval.opcode = tokentab3[i].opcode;
  2053.     return tokentab3[i].token;
  2054.       }
  2055.  
  2056.   /* See if it is a special token of length 2.  */
  2057.   for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
  2058.     if (!strncmp (tokstart, tokentab2[i].operator, 2))
  2059.       {
  2060.     lexptr += 2;
  2061.     yylval.opcode = tokentab2[i].opcode;
  2062.     return tokentab2[i].token;
  2063.       }
  2064.  
  2065.   switch (c = *tokstart)
  2066.     {
  2067.     case 0:
  2068.       return 0;
  2069.  
  2070.     case ' ':
  2071.     case '\t':
  2072.     case '\n':
  2073.       lexptr++;
  2074.       goto retry;
  2075.  
  2076.     case '\'':
  2077.       lexptr++;
  2078.       c = *lexptr++;
  2079.       if (c == '\\')
  2080.     c = parse_escape (&lexptr);
  2081.       yylval.lval = c;
  2082.       c = *lexptr++;
  2083.       if (c != '\'')
  2084.     error ("Invalid character constant.");
  2085.       return CHAR;
  2086.  
  2087.     case '(':
  2088.       paren_depth++;
  2089.       lexptr++;
  2090.       return c;
  2091.  
  2092.     case ')':
  2093.       if (paren_depth == 0)
  2094.     return 0;
  2095.       paren_depth--;
  2096.       lexptr++;
  2097.       return c;
  2098.  
  2099.     case ',':
  2100.       if (comma_terminates && paren_depth == 0)
  2101.     return 0;
  2102.       lexptr++;
  2103.       return c;
  2104.  
  2105.     case '.':
  2106.       /* Might be a floating point number.  */
  2107.       if (lexptr[1] < '0' || lexptr[1] > '9')
  2108.     goto symbol;        /* Nope, must be a symbol. */
  2109.       /* FALL THRU into number case.  */
  2110.  
  2111.     case '0':
  2112.     case '1':
  2113.     case '2':
  2114.     case '3':
  2115.     case '4':
  2116.     case '5':
  2117.     case '6':
  2118.     case '7':
  2119.     case '8':
  2120.     case '9':
  2121.       {
  2122.     /* It's a number.  */
  2123.     int got_dot = 0, got_e = 0, toktype;
  2124.     register char *p = tokstart;
  2125.     int hex = input_radix > 10;
  2126.  
  2127.     if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
  2128.       {
  2129.         p += 2;
  2130.         hex = 1;
  2131.       }
  2132.     else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
  2133.       {
  2134.         p += 2;
  2135.         hex = 0;
  2136.       }
  2137.  
  2138.     for (;; ++p)
  2139.       {
  2140.         if (!hex && !got_e && (*p == 'e' || *p == 'E'))
  2141.           got_dot = got_e = 1;
  2142.         else if (!hex && !got_dot && *p == '.')
  2143.           got_dot = 1;
  2144.         else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
  2145.              && (*p == '-' || *p == '+'))
  2146.           /* This is the sign of the exponent, not the end of the
  2147.          number.  */
  2148.           continue;
  2149.         /* We will take any letters or digits.  parse_number will
  2150.            complain if past the radix, or if L or U are not final.  */
  2151.         else if ((*p < '0' || *p > '9')
  2152.              && ((*p < 'a' || *p > 'z')
  2153.                   && (*p < 'A' || *p > 'Z')))
  2154.           break;
  2155.       }
  2156.     toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
  2157.         if (toktype == ERROR)
  2158.       {
  2159.         char *err_copy = (char *) alloca (p - tokstart + 1);
  2160.  
  2161.         bcopy (tokstart, err_copy, p - tokstart);
  2162.         err_copy[p - tokstart] = 0;
  2163.         error ("Invalid number \"%s\".", err_copy);
  2164.       }
  2165.     lexptr = p;
  2166.     return toktype;
  2167.       }
  2168.  
  2169.     case '+':
  2170.     case '-':
  2171.     case '*':
  2172.     case '/':
  2173.     case '%':
  2174.     case '|':
  2175.     case '&':
  2176.     case '^':
  2177.     case '~':
  2178.     case '!':
  2179.     case '@':
  2180.     case '<':
  2181.     case '>':
  2182.     case '[':
  2183.     case ']':
  2184.     case '?':
  2185.     case ':':
  2186.     case '=':
  2187.     case '{':
  2188.     case '}':
  2189.     symbol:
  2190.       lexptr++;
  2191.       return c;
  2192.  
  2193.     case '"':
  2194.       for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++)
  2195.     if (c == '\\')
  2196.       {
  2197.         c = tokstart[++namelen];
  2198.         if (c >= '0' && c <= '9')
  2199.           {
  2200.         c = tokstart[++namelen];
  2201.         if (c >= '0' && c <= '9')
  2202.           c = tokstart[++namelen];
  2203.           }
  2204.       }
  2205.       yylval.sval.ptr = tokstart + 1;
  2206.       yylval.sval.length = namelen - 1;
  2207.       lexptr += namelen + 1;
  2208.       return STRING;
  2209.     }
  2210.  
  2211.   if (!(c == '_' || c == '$'
  2212.     || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
  2213.     /* We must have come across a bad character (e.g. ';').  */
  2214.     error ("Invalid character '%c' in expression.", c);
  2215.  
  2216.   /* It's a name.  See how long it is.  */
  2217.   namelen = 0;
  2218.   for (c = tokstart[namelen];
  2219.        (c == '_' || c == '$' || (c >= '0' && c <= '9')
  2220.     || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
  2221.        c = tokstart[++namelen])
  2222.     ;
  2223.  
  2224.   /* The token "if" terminates the expression and is NOT 
  2225.      removed from the input stream.  */
  2226.   if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
  2227.     {
  2228.       return 0;
  2229.     }
  2230.  
  2231.   lexptr += namelen;
  2232.  
  2233.   /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
  2234.      and $$digits (equivalent to $<-digits> if you could type that).
  2235.      Make token type LAST, and put the number (the digits) in yylval.  */
  2236.  
  2237.   if (*tokstart == '$')
  2238.     {
  2239.       register int negate = 0;
  2240.       c = 1;
  2241.       /* Double dollar means negate the number and add -1 as well.
  2242.      Thus $$ alone means -1.  */
  2243.       if (namelen >= 2 && tokstart[1] == '$')
  2244.     {
  2245.       negate = 1;
  2246.       c = 2;
  2247.     }
  2248.       if (c == namelen)
  2249.     {
  2250.       /* Just dollars (one or two) */
  2251.       yylval.lval = - negate;
  2252.       return LAST;
  2253.     }
  2254.       /* Is the rest of the token digits?  */
  2255.       for (; c < namelen; c++)
  2256.     if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
  2257.       break;
  2258.       if (c == namelen)
  2259.     {
  2260.       yylval.lval = atoi (tokstart + 1 + negate);
  2261.       if (negate)
  2262.         yylval.lval = - yylval.lval;
  2263.       return LAST;
  2264.     }
  2265.     }
  2266.  
  2267.   /* Handle tokens that refer to machine registers:
  2268.      $ followed by a register name.  */
  2269.  
  2270.   if (*tokstart == '$') {
  2271.     for (c = 0; c < NUM_REGS; c++)
  2272.       if (namelen - 1 == strlen (reg_names[c])
  2273.       && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
  2274.     {
  2275.       yylval.lval = c;
  2276.       return REGNAME;
  2277.     }
  2278.     for (c = 0; c < NUM_STD_REGS; c++)
  2279.      if (namelen - 1 == strlen (std_regs[c].name)
  2280.      && !strncmp (tokstart + 1, std_regs[c].name, namelen - 1))
  2281.        {
  2282.      yylval.lval = std_regs[c].regnum;
  2283.      return REGNAME;
  2284.        }
  2285.   }
  2286.   /* Catch specific keywords.  Should be done with a data structure.  */
  2287.   switch (namelen)
  2288.     {
  2289.     case 8:
  2290.       if (!strncmp (tokstart, "unsigned", 8))
  2291.     return UNSIGNED;
  2292.       break;
  2293.     case 6:
  2294.       if (!strncmp (tokstart, "struct", 6))
  2295.     return STRUCT;
  2296.       if (!strncmp (tokstart, "signed", 6))
  2297.     return SIGNED;
  2298.       if (!strncmp (tokstart, "sizeof", 6))      
  2299.     return SIZEOF;
  2300.       break;
  2301.     case 5:
  2302.       if (!strncmp (tokstart, "union", 5))
  2303.     return UNION;
  2304.       if (!strncmp (tokstart, "short", 5))
  2305.     return SHORT;
  2306.       break;
  2307.     case 4:
  2308.       if (!strncmp (tokstart, "enum", 4))
  2309.     return ENUM;
  2310.       if (!strncmp (tokstart, "long", 4))
  2311.     return LONG;
  2312.       if (!strncmp (tokstart, "this", 4))
  2313.     {
  2314.       static const char this_name[] =
  2315.                  { CPLUS_MARKER, 't', 'h', 'i', 's', '\0' };
  2316.  
  2317.       if (lookup_symbol (this_name, expression_context_block,
  2318.                  VAR_NAMESPACE, 0, NULL))
  2319.         return THIS;
  2320.     }
  2321.       break;
  2322.     case 3:
  2323.       if (!strncmp (tokstart, "int", 3))
  2324.     return INT_KEYWORD;
  2325.       break;
  2326.     default:
  2327.       break;
  2328.     }
  2329.  
  2330.   yylval.sval.ptr = tokstart;
  2331.   yylval.sval.length = namelen;
  2332.  
  2333.   /* Any other names starting in $ are debugger internal variables.  */
  2334.  
  2335.   if (*tokstart == '$')
  2336.     {
  2337.       yylval.ivar =  lookup_internalvar (copy_name (yylval.sval) + 1);
  2338.       return VARIABLE;
  2339.     }
  2340.  
  2341.   /* Use token-type BLOCKNAME for symbols that happen to be defined as
  2342.      functions or symtabs.  If this is not so, then ...
  2343.      Use token-type TYPENAME for symbols that happen to be defined
  2344.      currently as names of types; NAME for other symbols.
  2345.      The caller is not constrained to care about the distinction.  */
  2346.   {
  2347.     char *tmp = copy_name (yylval.sval);
  2348.     struct symbol *sym;
  2349.     int is_a_field_of_this = 0;
  2350.     int hextype;
  2351.  
  2352.     sym = lookup_symbol (tmp, expression_context_block,
  2353.              VAR_NAMESPACE, &is_a_field_of_this, NULL);
  2354.     if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK) ||
  2355.         lookup_partial_symtab (tmp))
  2356.       {
  2357.     yylval.ssym.sym = sym;
  2358.     yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  2359.     return BLOCKNAME;
  2360.       }
  2361.     if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
  2362.         {
  2363.       yylval.tsym.type = SYMBOL_TYPE (sym);
  2364.       return TYPENAME;
  2365.         }
  2366.     if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
  2367.     return TYPENAME;
  2368.  
  2369.     /* Input names that aren't symbols but ARE valid hex numbers,
  2370.        when the input radix permits them, can be names or numbers
  2371.        depending on the parse.  Note we support radixes > 16 here.  */
  2372.     if (!sym && 
  2373.         ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) ||
  2374.          (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
  2375.       {
  2376.      YYSTYPE newlval;    /* Its value is ignored.  */
  2377.     hextype = parse_number (tokstart, namelen, 0, &newlval);
  2378.     if (hextype == INT)
  2379.       {
  2380.         yylval.ssym.sym = sym;
  2381.         yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  2382.         return NAME_OR_INT;
  2383.       }
  2384.     if (hextype == UINT)
  2385.       {
  2386.         yylval.ssym.sym = sym;
  2387.         yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  2388.         return NAME_OR_UINT;
  2389.       }
  2390.       }
  2391.  
  2392.     /* Any other kind of symbol */
  2393.     yylval.ssym.sym = sym;
  2394.     yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  2395.     return NAME;
  2396.   }
  2397. }
  2398.  
  2399. /* ARGSUSED */
  2400. static void
  2401. yyerror (msg)
  2402.      char *msg;
  2403. {
  2404.   error ("Invalid syntax in expression.");
  2405. }
  2406.  
  2407. /* Return a null-terminated temporary copy of the name
  2408.    of a string token.  */
  2409.  
  2410. static char *
  2411. copy_name (token)
  2412.      struct stoken token;
  2413. {
  2414.   bcopy (token.ptr, namecopy, token.length);
  2415.   namecopy[token.length] = 0;
  2416.   return namecopy;
  2417. }
  2418.  
  2419. /* Reverse an expression from suffix form (in which it is constructed)
  2420.    to prefix form (in which we can conveniently print or execute it).  */
  2421.  
  2422. static void prefixify_subexp ();
  2423.  
  2424. static void
  2425. prefixify_expression (expr)
  2426.      register struct expression *expr;
  2427. {
  2428.   register int len = sizeof (struct expression) +
  2429.                     expr->nelts * sizeof (union exp_element);
  2430.   register struct expression *temp;
  2431.   register int inpos = expr->nelts, outpos = 0;
  2432.  
  2433.   temp = (struct expression *) alloca (len);
  2434.  
  2435.   /* Copy the original expression into temp.  */
  2436.   bcopy (expr, temp, len);
  2437.  
  2438.   prefixify_subexp (temp, expr, inpos, outpos);
  2439. }
  2440.  
  2441. /* Return the number of exp_elements in the subexpression of EXPR
  2442.    whose last exp_element is at index ENDPOS - 1 in EXPR.  */
  2443.  
  2444. static int
  2445. length_of_subexp (expr, endpos)
  2446.      register struct expression *expr;
  2447.      register int endpos;
  2448. {
  2449.   register int oplen = 1;
  2450.   register int args = 0;
  2451.   register int i;
  2452.  
  2453.   if (endpos < 0)
  2454.     error ("?error in length_of_subexp");
  2455.  
  2456.   i = (int) expr->elts[endpos - 1].opcode;
  2457.  
  2458.   switch (i)
  2459.     {
  2460.       /* C++  */
  2461.     case OP_SCOPE:
  2462.       oplen = 4 + ((expr->elts[endpos - 2].longconst
  2463.             + sizeof (union exp_element))
  2464.            / sizeof (union exp_element));
  2465.       break;
  2466.  
  2467.     case OP_LONG:
  2468.     case OP_DOUBLE:
  2469.       oplen = 4;
  2470.       break;
  2471.  
  2472.     case OP_VAR_VALUE:
  2473.     case OP_LAST:
  2474.     case OP_REGISTER:
  2475.     case OP_INTERNALVAR:
  2476.       oplen = 3;
  2477.       break;
  2478.  
  2479.     case OP_FUNCALL:
  2480.       oplen = 3;
  2481.       args = 1 + expr->elts[endpos - 2].longconst;
  2482.       break;
  2483.  
  2484.     case UNOP_CAST:
  2485.     case UNOP_MEMVAL:
  2486.       oplen = 3;
  2487.       args = 1;
  2488.       break;
  2489.  
  2490.     case STRUCTOP_STRUCT:
  2491.     case STRUCTOP_PTR:
  2492.       args = 1;
  2493.     case OP_STRING:
  2494.       oplen = 3 + ((expr->elts[endpos - 2].longconst
  2495.             + sizeof (union exp_element))
  2496.            / sizeof (union exp_element));
  2497.       break;
  2498.  
  2499.     case TERNOP_COND:
  2500.       args = 3;
  2501.       break;
  2502.  
  2503.     case BINOP_ASSIGN_MODIFY:
  2504.       oplen = 3;
  2505.       args = 2;
  2506.       break;
  2507.  
  2508.       /* C++ */
  2509.     case OP_THIS:
  2510.       oplen = 2;
  2511.       break;
  2512.  
  2513.     default:
  2514.       args = 1 + (i < (int) BINOP_END);
  2515.     }
  2516.  
  2517.   while (args > 0)
  2518.     {
  2519.       oplen += length_of_subexp (expr, endpos - oplen);
  2520.       args--;
  2521.     }
  2522.  
  2523.   return oplen;
  2524. }
  2525.  
  2526. /* Copy the subexpression ending just before index INEND in INEXPR
  2527.    into OUTEXPR, starting at index OUTBEG.
  2528.    In the process, convert it from suffix to prefix form.  */
  2529.  
  2530. static void
  2531. prefixify_subexp (inexpr, outexpr, inend, outbeg)
  2532.      register struct expression *inexpr;
  2533.      struct expression *outexpr;
  2534.      register int inend;
  2535.      int outbeg;
  2536. {
  2537.   register int oplen = 1;
  2538.   register int args = 0;
  2539.   register int i;
  2540.   int *arglens;
  2541.   enum exp_opcode opcode;
  2542.  
  2543.   /* Compute how long the last operation is (in OPLEN),
  2544.      and also how many preceding subexpressions serve as
  2545.      arguments for it (in ARGS).  */
  2546.  
  2547.   opcode = inexpr->elts[inend - 1].opcode;
  2548.   switch (opcode)
  2549.     {
  2550.       /* C++  */
  2551.     case OP_SCOPE:
  2552.       oplen = 4 + ((inexpr->elts[inend - 2].longconst
  2553.             + sizeof (union exp_element))
  2554.            / sizeof (union exp_element));
  2555.       break;
  2556.  
  2557.     case OP_LONG:
  2558.     case OP_DOUBLE:
  2559.       oplen = 4;
  2560.       break;
  2561.  
  2562.     case OP_VAR_VALUE:
  2563.     case OP_LAST:
  2564.     case OP_REGISTER:
  2565.     case OP_INTERNALVAR:
  2566.       oplen = 3;
  2567.       break;
  2568.  
  2569.     case OP_FUNCALL:
  2570.       oplen = 3;
  2571.       args = 1 + inexpr->elts[inend - 2].longconst;
  2572.       break;
  2573.  
  2574.     case UNOP_CAST:
  2575.     case UNOP_MEMVAL:
  2576.       oplen = 3;
  2577.       args = 1;
  2578.       break;
  2579.  
  2580.     case STRUCTOP_STRUCT:
  2581.     case STRUCTOP_PTR:
  2582.       args = 1;
  2583.     case OP_STRING:
  2584.       oplen = 3 + ((inexpr->elts[inend - 2].longconst
  2585.             + sizeof (union exp_element))
  2586.            / sizeof (union exp_element));
  2587.            
  2588.       break;
  2589.  
  2590.     case TERNOP_COND:
  2591.       args = 3;
  2592.       break;
  2593.  
  2594.     case BINOP_ASSIGN_MODIFY:
  2595.       oplen = 3;
  2596.       args = 2;
  2597.       break;
  2598.  
  2599.       /* C++ */
  2600.     case OP_THIS:
  2601.       oplen = 2;
  2602.       break;
  2603.  
  2604.     default:
  2605.       args = 1 + ((int) opcode < (int) BINOP_END);
  2606.     }
  2607.  
  2608.   /* Copy the final operator itself, from the end of the input
  2609.      to the beginning of the output.  */
  2610.   inend -= oplen;
  2611.   bcopy (&inexpr->elts[inend], &outexpr->elts[outbeg],
  2612.      oplen * sizeof (union exp_element));
  2613.   outbeg += oplen;
  2614.  
  2615.   /* Find the lengths of the arg subexpressions.  */
  2616.   arglens = (int *) alloca (args * sizeof (int));
  2617.   for (i = args - 1; i >= 0; i--)
  2618.     {
  2619.       oplen = length_of_subexp (inexpr, inend);
  2620.       arglens[i] = oplen;
  2621.       inend -= oplen;
  2622.     }
  2623.  
  2624.   /* Now copy each subexpression, preserving the order of
  2625.      the subexpressions, but prefixifying each one.
  2626.      In this loop, inend starts at the beginning of
  2627.      the expression this level is working on
  2628.      and marches forward over the arguments.
  2629.      outbeg does similarly in the output.  */
  2630.   for (i = 0; i < args; i++)
  2631.     {
  2632.       oplen = arglens[i];
  2633.       inend += oplen;
  2634.       prefixify_subexp (inexpr, outexpr, inend, outbeg);
  2635.       outbeg += oplen;
  2636.     }
  2637. }
  2638.  
  2639. /* This page contains the two entry points to this file.  */
  2640.  
  2641. /* Read a C expression from the string *STRINGPTR points to,
  2642.    parse it, and return a pointer to a  struct expression  that we malloc.
  2643.    Use block BLOCK as the lexical context for variable names;
  2644.    if BLOCK is zero, use the block of the selected stack frame.
  2645.    Meanwhile, advance *STRINGPTR to point after the expression,
  2646.    at the first nonwhite character that is not part of the expression
  2647.    (possibly a null character).
  2648.  
  2649.    If COMMA is nonzero, stop if a comma is reached.  */
  2650.  
  2651. struct expression *
  2652. parse_c_1 (stringptr, block, comma)
  2653.      char **stringptr;
  2654.      struct block *block;
  2655.      int comma;
  2656. {
  2657.   struct cleanup *old_chain;
  2658.  
  2659.   lexptr = *stringptr;
  2660.  
  2661.   paren_depth = 0;
  2662.   type_stack_depth = 0;
  2663.  
  2664.   comma_terminates = comma;
  2665.  
  2666.   if (lexptr == 0 || *lexptr == 0)
  2667.     error_no_arg ("expression to compute");
  2668.  
  2669.   old_chain = make_cleanup (free_funcalls, 0);
  2670.   funcall_chain = 0;
  2671.  
  2672.   expression_context_block = block ? block : get_selected_block ();
  2673.  
  2674.   namecopy = (char *) alloca (strlen (lexptr) + 1);
  2675.   expout_size = 10;
  2676.   expout_ptr = 0;
  2677.   expout = (struct expression *)
  2678.     xmalloc (sizeof (struct expression)
  2679.          + expout_size * sizeof (union exp_element));
  2680.   make_cleanup (free_current_contents, &expout);
  2681.   if (yyparse ())
  2682.     yyerror (NULL);
  2683.   discard_cleanups (old_chain);
  2684.   expout->nelts = expout_ptr;
  2685.   expout = (struct expression *)
  2686.     xrealloc (expout,
  2687.           sizeof (struct expression)
  2688.           + expout_ptr * sizeof (union exp_element));
  2689.   prefixify_expression (expout);
  2690.   *stringptr = lexptr;
  2691.   return expout;
  2692. }
  2693.  
  2694. /* Parse STRING as an expression, and complain if this fails
  2695.    to use up all of the contents of STRING.  */
  2696.  
  2697. struct expression *
  2698. parse_c_expression (string)
  2699.      char *string;
  2700. {
  2701.   register struct expression *exp;
  2702.   exp = parse_c_1 (&string, 0, 0);
  2703.   if (*string)
  2704.     error ("Junk after end of expression.");
  2705.   return exp;
  2706. }
  2707.  
  2708. static void 
  2709. push_type (tp)
  2710.      enum type_pieces tp;
  2711. {
  2712.   if (type_stack_depth == type_stack_size)
  2713.     {
  2714.       type_stack_size *= 2;
  2715.       type_stack = (union type_stack_elt *)
  2716.     xrealloc (type_stack, type_stack_size * sizeof (*type_stack));
  2717.     }
  2718.   type_stack[type_stack_depth++].piece = tp;
  2719. }
  2720.  
  2721. static void
  2722. push_type_int (n)
  2723.      int n;
  2724. {
  2725.   if (type_stack_depth == type_stack_size)
  2726.     {
  2727.       type_stack_size *= 2;
  2728.       type_stack = (union type_stack_elt *)
  2729.     xrealloc (type_stack, type_stack_size * sizeof (*type_stack));
  2730.     }
  2731.   type_stack[type_stack_depth++].int_val = n;
  2732. }
  2733.  
  2734. static enum type_pieces 
  2735. pop_type ()
  2736. {
  2737.   if (type_stack_depth)
  2738.     return type_stack[--type_stack_depth].piece;
  2739.   return tp_end;
  2740. }
  2741.  
  2742. static int
  2743. pop_type_int ()
  2744. {
  2745.   if (type_stack_depth)
  2746.     return type_stack[--type_stack_depth].int_val;
  2747.   /* "Can't happen".  */
  2748.   return 0;
  2749. }
  2750.  
  2751. void
  2752. _initialize_expread ()
  2753. {
  2754.   type_stack_size = 80;
  2755.   type_stack_depth = 0;
  2756.   type_stack = (union type_stack_elt *)
  2757.     xmalloc (type_stack_size * sizeof (*type_stack));
  2758. }
  2759.